O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

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

Adding an Objective-C Class

Now that you have interoperated from Objective-C to Swift, your next task is to interoperate from Swift to Objective-C. You will create a new Objective-C class to make a default image for new contacts. Your Swift class NewContactViewController will use this new Objective-C class. This simulates a fairly common reality: An existing project will often have a number of Objective-C classes that are needed in the Swift components of the project.

Create a new Objective-C file that is a Cocoa Touch Class and call it ImageFactory. Its job will be to create a new contact’s default image. Make this new class a subclass of NSObject. Be sure to select Objective-C as the language for this class.

Before you begin ...

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