Can't use Swift classes inside Objective-C

前端 未结 25 2390
野趣味
野趣味 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:26

    There is two condition,

    • Use your swift file in objective c file.
    • Use your objective c file in swift file.

    So, For that purpose, you have to follow this steps:

    • Add your swift file in an objective-c project or vice-versa.
    • Create header(.h) file.
    • Go to Build Settings and perform below steps with search,

      1. search for this text "brid" and set a path of your header file.
      2. "Defines Module": YES.
      3. "Always Embed Swift Standard Libraries" : YES.
      4. "Install Objective-C Compatibility Header" : YES.

    After that, clean and rebuild your project.

    Use your swift file in objective c file.

    In that case,First write "@objc" before your class in swift file.

    After that ,In your objective c file, write this,

      #import "YourProjectName-Swift.h"
    

    Use your objective c file in swift file.

    In that case, In your header file, write this,

      #import "YourObjective-c_FileName.h"
    

    I hope this will help you.

提交回复
热议问题