简体   繁体   中英

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?

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM