Swift “Bridging-Header.h” file not allowing me to instantiate objective-c classes in .swift files

后端 未结 5 1507
执笔经年
执笔经年 2020-12-05 03:10

When X-code tries to create a bridging header automatically, it crashes every single time, so I followed the instructions on how to manually create a bridging header. (Creat

相关标签:
5条回答
  • 2020-12-05 03:33

    You need to add it to your target's build settings:

    1. In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.

    2. Set "Objective-C Bridging Header" to <#PROJECT_NAME>-Bridging-Header.h

    3. I'm not sure of the correct value for "Install Objective-C Compatibility Header", but it's a yes/no, so you can toggle that if it doesn't work at first.

    0 讨论(0)
  • 2020-12-05 03:34

    it could help setting the name of the bridging header with its Project root, as "MyProject/MyProject-Bridging-Header.h" into the string value of the Swift Compiler Build key 'Objective-C Bridging Header'

    0 讨论(0)
  • 2020-12-05 03:40

    I tried to create a bridging header myself but for some reason Xcode didn't like it. So i deleted my custom one, imported an Obj C file which made Xcode ask if I wanted it to create one for me.

    I clicked yes, and it worked!

    0 讨论(0)
  • 2020-12-05 03:46
    1. Add a header file to your project with the name "[your-project-name]-Bridging-Header.h

    1. Go to Build Settings > Build Options and set "Embedded Content Contains Swift Code" to "Yes"

    2. Go to Build Settings > Linking and add "@executable_path/Frameworks" to Runpath Search Paths

    Build your project now!

    0 讨论(0)
  • 2020-12-05 03:50

    1) create a file called "FMDB-Bridging-Header.h"

    inside this file type the following: #import "FMDB.h"

    3) go to Build Settings -> Swift Compiler - Code Generation - add to 'Objective-C Bridging Header': FMDB-Bridging-Header.h

    or if it was placed inside a folder in your project:

    FolderName/FMDB-Bridging-Header.h

    0 讨论(0)
提交回复
热议问题