Home » How - To / Tutorial » Programming » How To Use Objective-C Classess in iOS Swift

How To Use Objective-C Classess in iOS Swift

You might need to use of the objective-C classes in Swift. This is possible. Just do the following:

  1. Add .m (Objective-C implementation)
    This file, that is, a .m one, should be added to the class and named CustomObject.m
  2. Add the Bridging Header
    During the addition of the .m file, a dialog will appear which looks as follows: Just click on Yes.
    Objective-C-Class-in-Swift-iOS-Programming How To Use Objective-C Classess in iOS Swift
  3. Add .h, the Objective-C Header
    Add another .h. Give it the name CustomObject.h
  4. Build the Objective-C class
    In CustomObject.h, this should be as follows:

    In CustomObject.m, t should be as follows:
  5. Add a class to the Bridging-Header This should be:
  6. Use your Object

The bridging header is so useful since with it, there is no need to import explicitly. You are done, so you can safely use the classes.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website