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 Mac or iOS 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 DefaultImage. 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 ...
Get Swift Programming: The Big Nerd Ranch Guide 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.