Chapter 12. Collections

Contrasting the support for collections between Objective-C and Swift initially seems a little unfair. The collections we know, love, and take for granted in Objective-C (NSArray, NSDictionary, and friends) are actually part of the Foundation framework, which leaves native C arrays as the only direct language-to-language comparison. Given, however, the extent to which the Foundation collections are used in iOS and OS X development, comparing their usage to Swift native collections does make sense.

Swift comes with two native collection types—arrays and dictionaries—and like strings in Swift they can be made immutable by declaring as a constant rather than as a variable. As collections they draw immediate parallels between ...

Get Swift Translation Guide for Objective-C Users: Develop and Design 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.