-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Swift Second Edition
By :

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.
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 separate call is always contained within a single set of square brackets. In this case, we are first calling the alloc
method on the NSArray
class. This returns a newly allocated variable that is of the type NSArray
.
In contrast to Swift, Objective...
Change the font size
Change margin width
Change background colour