O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

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

The Objective-C class - accessing Swift code from Objective-C

Once the user enters their name and presses the Get Message button, we will create an instance of the Swift MessageBuilder class in the Objective-C code and call the getPersonlizedMessage() method to generate the message to be displayed.

When we access Swift code from Objective-C, we rely on an Xcode-generated header file to expose the Swift classes. This automatically generated header file declares the interface for the Swift classes. The name of this header file is the name of your project followed by - Swift.h, so the name of the header file for our project is ObjectiveCExample-Swift.h. Therefore, the first step to access the Swift code from Objective-C is to import this header ...

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