This interface is newly added in Swift 2. It just has one function (description). According to Apple’s document, “This textual representation is used when values are written to an output stream, for example, by print.”
Structures and enumerations are value types. The properties of a value type cannot be modified from within its instance methods. However, you can change them from within its instance methods by using “mutating” keyword.
“precondition” can check a necessary condition to detect whether the program can proceed or not even in production code. While “assert” just works in debug mode by default.
If the compiler can infer the type, you can use this syntax to empty the dictionary.
a ?? b is equivalent to
a != nil ? a! : b
SequenceType, GeneratorType and IndexingGenerator
SequenceType can be iterated with a for…in loop. GeneratorType encapsulates iteration state and interface for iteration over a sequence. IndexingGenerator is a generator for an arbitrary collection. The example below is from Apple “Exploring San Francisco” demo code.
x == y implies
x.hashValue == y.hashValue and Hashable extends Equatable. Instances of this type can be keys of the dictionary.
weak vs unowned
weak and unowned are used to break a strong reference cycle.
A weak reference is a reference that does not keep a strong hold on the instance it refers to, and so does not stop ARC from disposing of the referenced instance.
Like weak references, an unowned reference does not keep a strong hold on the instance it refers to. Unlike a weak reference, however, an unowned reference is assumed to always have a value. Because of this, an unowned reference is always defined as a non-optional type.
private(set) or internal(set)
A property is marked with a private(set) modifier to indicate that the property should be settable only from within the same source file.