Can't use Swift classes inside Objective-C

前端 未结 25 2029
野趣味
野趣味 2020-11-22 08:10

I try to integrate Swift code in my app.My app is written in Objective-C and I added a Swift class. I\'ve done everything described he

25条回答
  •  北海茫月
    2020-11-22 08:27

    Allow Xcode to do its work, do not add/create Swift header manually. Just add @objc before your Swift class ex.

    @objc class YourSwiftClassName: UIViewController
    

    In your project setting search for below flags and change it to YES (Both Project and Target)

    Defines Module : YES
    Always Embed Swift Standard Libraries : YES
    Install Objective-C Compatibility Header : YES
    

    Then clean the project and build once, after build succeed (it should probably) import below header file in your objective-c class .m file

    #import "YourProjectName-Swift.h" 
    

    Boooom!

提交回复
热议问题