*An NSArray is heterogeneous, meaning that it can contain Cocoa objects of different types. Swift arrays are homogeneous, meaning that each Swift Array is guaranteed to contain only one type of object.
However, you can still define a single Swift Array so it stores various types of Cocoa objects by specifying that the one type is AnyObject, since every Cocoa type is also a subtype of this.
*Dictionaries are strongly typed, and you must have known key and value types. NSDictionary objects are able to take any NSObject as a key and store any object as a value.
*Note that subscripting syntax on dictionaries returns an optional. If the dictionary doesn't contain a value for a particular key, the optional is nil; if it does contain a value for that key you could get the wrapped value.
if let ellensCat = cats["Ellen"] { println("Ellen's cat is named \(ellensCat).") } else { println("Ellen's cat's name not found!") }
Because of that, it's a good idea to use the if let optional-unwrapping syntax to access values in a dictionary.
*Swift sets are type-specific -- all the items in a Swift Set must be of the same type.
*Creating Swift dictionaries is significantly slower than creating NSMutableDictionaries -- but both degrade at roughly the same O(n) rate.
*Set creation is considerably slower -- that's the price you pay for checking if every single item in a data structure is unique.
*Removing and looking up are both around O(1) performance degradations across Swift and Foundation. This is largely because set structures use hashes to check for equality, and the hashes can be calculated and stored in sorted order. This makes set lookup considerably faster than array lookup.
*NSCountedSet tracks how many times you've added an object to a mutable set. It inherits from NSMutableSet, so if you try to add the same object again, it's only in the set once.
*NSOrderedSet inherits from NSObject.
*You can use ordered sets as an alternative to arrays when element order matters and performance while testing whether an object is contained in the set is a consideration -- testing for membership of an array is slower than testing for membership of a set.
*An NSIndexSet is an immutable collection of unique unsigned integers intended to represent indexes of an array.