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 bridging header file - part 2

Now that we have created the Messages Objective-C class, we will need to expose it to our Swift code. Those who are familiar with Objective-C (or any C-based language), will know that we need to import the class header using the #import or #include directive prior to using it within another class. In that same context, we need to import the header file of any Objective-C class in the Objective-C bridging header file prior to using that class in our Swift code. Therefore, to allow our Swift code to access the Messages Objective-C class, we need to add the following line to the Objective-C bridging header file that Xcode created for us:

#import "Messages.h" 

Yep, that's it. Pretty simple. Now, let's ...

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