RTzhong
RTzhong

Reputation: 205

Swift can't use ObjectiveC classes

I want use JSQMessagesViewController in my project(using swift), I didn't use pods since I would modify some of the ObjectiveC code, so I just pull the Project into my own iOS project. And I include the OC project file in my Project-Bridging-Header.h file, it builds successfully. However, when I use the objectiveC classes, the compiler cannot recognize it.

Is there some configuration that I missed, or if I did it in a completely wrong way?

Upvotes: 0

Views: 184

Answers (2)

rikky
rikky

Reputation: 76

You have to use bridging header for the same . Bridging header helps you to access objective c code in your swift code .

For that purpose you have to create 1 header file like FileName-Bridging-Header.h

and add that file path in "Build setting -> Objective-C Bridging Header" and set your file path like "ProjectName/FileName-Bridging-Header.h"

Upvotes: 4

Karlos
Karlos

Reputation: 1661

Try the solution given below. It worked for me.

Go to Project traget -> Build Settings -> Objective-C Bridging Header

Set this as your Projectfolder/projectname-Bridging-Header.h

Add you "sample.h" and "sample.m" file in the project folder and add import the sample.h in the "projectname-Bridging-Header.h" file as given below:

#import "sample.h"

save it and check if you get access to the function of Objective-C functions in your swift code.

Upvotes: 1

Related Questions