Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. ### Problem
  2. You can't use bridging headers within a framework.
  3.  
  4. #### Solution 1 (umbrella header):
  5. 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).
  6.  
  7. 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&mdash;Inspectors&mdash;pane) from `Project` to `Public`.
  8. 2. Open umbrella header (`<FrameworkName>.h`) and import the required header as:
  9.  
  10. ```objc
  11. #import <FrameworkName/objc-header.h>
  12. ```
  13.  
  14. This effectively makes this header public and available to **both** your own framework and anyone who uses it.
  15.  
  16. *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.
  17.  
  18. #### Solution 2 (module map):
  19.  
  20. 1. Create a file named `module.modulemap` in the **root** of your project with the following contents:
  21.  
  22. ```swift
  23. framework module FrameworkName {
  24. umbrella header "FrameworkName.h"
  25.  
  26. header "objc-header.h"
  27.  
  28. export *
  29. module * { export * }
  30. }
  31. ```
  32.  
  33. 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:
  34.  
  35. ```swift
  36. // ...
  37. private header "objc-header.h"
  38. // ...
  39. ```
  40.  
  41. 2. In Build Setting set `Module Map File` to `module.modulemap`
  42.  
  43. 3. Clean the build directory (&#x21e7;&#x2318;K) and build the project (&#x2318;B)
  44.  
  45. <hr>
  46.  
  47. ~~*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&mdash;the compiler was spitting something like: *Redifinition of <FrameworkName> module*.~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement