简体   繁体   中英

I need to use a swift class in objective-c and cannot setup my Emilos-Swift.h bridging file to resolve any swift classes in objective-c

Cannot get Xcode to generate the bridging file so it's currently empty and cannot find any guide/docs on what needs to be in the file. The empty bridging file is being imported in the .m where the class is needed. Swift file using @objcmembers on class definition.

How and what should go into the bridging file. Have looked for two days trying to make this work with no success.

Is there a way to turn back on the automatic generation of the bridging file in Xcode? Any docs on the contents of the bridging file?

Don't confuse the two kinds of header. The "bridging header" is for Swift to see Objective-C code. It isn't relevant here.

The way Objective-C sees Swift code is through the generated interface header . You can see its name in your app target build settings:

在此处输入图片说明

So what that tells you is that if you #import "MomApp2-Swift.h" in your .m file, your Objective-C code will see your code that is exposed from Swift.

If you want to see what is in that generated interface header, then after you've done that import, Command-click on the file name.

To use a Swift class on objective-c you need to be sure that your class inherits from NSObject , has an @objc annotation on class definition and other elements that you want to use need to be marked with @objc . @objcmembers marks all elements visible from an Objc class located on file that imports the "project-Swift.h"

You may not need all class members visible from Objective-c

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