Using AnyObject

With Swift you can make an array of AnyObjects. You will see this done frequently where something has a return value of [AnyObject]. This is a nonspecific type to represent any type of class. Objective-C does not have strictly typed arrays, so in order to interface with Cocoa APIs properly, you need some flexibility to return arrays so that they can contain a mixed bag. You will often see Cocoa APIs return [AnyObject].

Get Learning Swift™ Programming 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.