Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Problem
- You can't use bridging headers within a framework.
- #### Solution 1 (umbrella header):
- Xcode will automatically create umbrella header for you Cocoa Framework project. That will be the file named `<FrameworkName>.h` in the `<FrameworkName>` group/folder (where the rest of your sources are).
- 1. To include the required Obj-C header you need to set it as `Public`: select it in the project explorer (left pane) and change the property `Target Membership` (left—Inspectors—pane) from `Project` to `Public`.
- 2. Open umbrella header (`<FrameworkName>.h`) and import the required header as:
- ```objc
- #import <FrameworkName/objc-header.h>
- ```
- This effectively makes this header public and available to **both** your own framework and anyone who uses it.
- *Note*: If you import the header as a local file, i.e. in quotes, e.g. `#import "objc-header.h"`, you likely to hit the compiler error telling you are trying to include a non-modular header.
- #### Solution 2 (module map):
- 1. Create a file named `module.modulemap` in the **root** of your project with the following contents:
- ```swift
- framework module FrameworkName {
- umbrella header "FrameworkName.h"
- header "objc-header.h"
- export *
- module * { export * }
- }
- ```
- In case you want to keep the definitions from `objc-header.h` private from the users of your framework you can add `private` qualifier like so:
- ```swift
- // ...
- private header "objc-header.h"
- // ...
- ```
- 2. In Build Setting set `Module Map File` to `module.modulemap`
- 3. Clean the build directory (⇧⌘K) and build the project (⌘B)
- <hr>
- ~~*Note*: There are options in the Build Settings of the project to specify the `Module Map File` and `Module Private File`, but I couldn't manage to make them work—the compiler was spitting something like: *Redifinition of <FrameworkName> module*.~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement