O'Reilly logo

Learning Swift by Andrew J Wagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Containers

Objective-C has the same core containers that Swift does with the two exceptions that they are named slightly differently and all 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 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 defined a variable called array that is a reference to the NSArray type. 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 separate call is always contained ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required