user3700298
user3700298

Reputation: 11

Calling a method in objective-c extension class in swift

How can I use any of the methods which are implemented in an extension in objective-c, and use it in my swift class? I have a swift class in which I am trying to call a extension method which is implemented in objective-c.

Upvotes: 0

Views: 527

Answers (2)

user3700298
user3700298

Reputation: 11

I had forgotten to add -ObjC in the Other Linker Flags in the build settings for the target. It worked after setting it.

Upvotes: 0

Hunter Monk
Hunter Monk

Reputation: 1997

First, you need to create a bridging header file. To create this, go to File -> New -> File -> Objective-C File. Name this file whatever you want, and press next. You can just delete it later.

After pressing next, it will prompt you asking if you would like to configure a bridging header. Press ok.

Inside the bridging header, just add:

#import "NameOfYourExtension.h"

and it will be available in all of your swift files.

Upvotes: 1

Related Questions