Containers
Objective-C has the same exact core containers that Swift does, with the two exceptions being that they are named slightly differently, and all of the containers in Objective-C are reference types because of the basic requirement that all Objective-C types must be reference types.
Arrays
In Objective-C arrays are called NSArray
. Let's take a look at the initialization of an array in both Swift and Objective-C side-by-side:
var array = [Int]() NSArray *array = [NSArray alloc]; array = [array init];
We have defined a variable called array
that is a reference to the type NSArray
. We then assign it to a newly allocated instance of NSArray
. The square bracket notation in Objective-C allows us to call methods on a type or on an instance. Each ...
Get Swift: Developing iOS Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.