O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

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

Working with Foundation Types

In Objective-C, a number of familiar types are implemented as classes as part of the Foundation framework: NSString, NSNumber, NSArray, NSDictionary, and NSSet. Because Cocoa was built for Objective-C, you will often run into these classes when working with the Cocoa APIs. The good news is that Apple has made transitioning between the Swift and Foundation (Objective-C) counterparts relatively painless. They are toll-free bridged, meaning that there is minimal computational cost in converting between the two.

Basic bridging

Swift types are automatically bridged to their Foundation counterparts:

l​e​t​ ​s​t​r​i​n​g​ ​=​ ​"​H​o​w​d​y​"​ l​e​t​ ​o​b​j​c​S​t​r​i​n​g​:​ ​N​S​S​t​r​i​n​g​ ​=​ ...

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