|
|
|
|
|
by torpidor
2877 days ago
|
|
> That means that greeter and greeter1 are just two references to the exact same underlying object They are two references that differ in type. It is a feature in Swift (and any strongly-typed language) that references are typed and when types differ, behaviors can differ. I understand you disagree with this design principle but it is an inherent property of strong type systems that have reference semantics. > two distinct value type instances “Nope.” There isn’t any such thing as a “value type instance” since instances are a semantic of reference types. > objects shouldn’t be different depending on how you look at them The “difference” here is only in the types, so this statement is equivalent to “references shouldn’t be different depending on their type.” This statement implies that types should be useless |
|
Hmm..
"An instance of a class is traditionally known as an object. However, Swift structures and classes are much closer in functionality than in other languages, and much of this chapter describes functionality that applies to instances of either a class or a structure type. Because of this, the more general term instance is used."
and
"Structure and Class Instances"
..
"Structures and Enumerations Are Value Types
A value type is a type whose value is copied when it’s assigned to a variable or constant, or when it’s passed to a function.
You’ve actually been using value types extensively throughout the previous chapters. In fact, all of the basic types in Swift—integers, floating-point numbers, Booleans, strings, arrays and dictionaries—are value types, and are implemented as structures behind the scenes."
https://docs.swift.org/swift-book/LanguageGuide/ClassesAndSt...
> “references shouldn’t be different depending on their type.”
You are confusing the type of the variable with the type of the object/value contained in the variable. A static type system is there to ensure that the type of the variable matches the type its contents.