Build swift framework that used 3rd party Objective-C framework

I am trying to build a swift framework that used 3rd party Objective-C framework, but I get the following error:

"include of non-modular header inside framework module".

Removing the header includes of the 3rd party Objective-C framework makes the error go away, but that is not what I want.

I tried to do the exact same thing by building a swift app instead of framework, and the error does not occur.


Am I missing any configuration in my swift framework project?

I did try to change the "Always Search User Parths" setting, but there was no difference.

I did try to change the "Allow Non-modular Includes in Framework Modules" setting, but there was no difference.

Replies

Does the Objective-C framework define a module? Look for the Defines Module (

DEFINES_MODULE
) build setting.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

No, it does not.

I make some dummy Objective-C frameworks for testing and noticed that the "Defines Module" setting makes a difference.

Thank you

… the "Defines Module" setting makes a difference.

Right. For Swift to be able to access a framework it must define a module. Defines Module is an easy way to do that, although there are other options (search the build settings for “module” for more info on those).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Is there any way to expose the objects, methods and types that are in the third party obective-c framework? I seem to be missing something either in my search paths or what I am including as public headers.

Thanks

I’m not sure which steps you’re missing but I just tried the following here in my office and it worked a treat:

  1. I created a new project, MyFrameworkClient, from the iOS > Single View App template, setting the language to Swift.

  2. I created a new target, MyFramework, from the iOS > Cocoa Touch Framework template, setting the language to Objective-C.

    Note This template sets the Defines Module (

    DEFINES_MODULE
    ) build setting by default.
  3. In the project navigator’s

    MyFramework
    group, I created a new file from the iOS > Cocoa Touch Class template with the following details:
    • Name: MyObjCClass

    • Subclass of: NSObject

    • Language: Objective-C

  4. In

    MyObjCClass.h
    I added this method:
    + (void)myObjCMethod;

    -

  5. In

    MyObjCClass.m
    I add its implementation:
    + (void)myObjCMethod {
        NSLog(@"Hello Cruel World!");
    }

    -

  6. In

    MyFramework.h
    , I added this line to the end:
    #import <MyFramework/MyObjCClass.h>

    -

  7. I selected

    MyObjCClass.h
    in the project navigator and then brought up the file inspector (View > Utilities > Show File Inspector). In the Target Membership list I selected Public from the popup next to MyFramework.
  8. I switched to the MyFramework scheme and built that.

  9. I switched to the MyFrameworkClient scheme and built that.

  10. In

    ViewController.swift
    , I added this line to the imports section:
    import MyFramework

    and this line to the body of

    viewDidLoad()
    :
    MyObjCClass.myObjCMethod()

    -

  11. I built and ran the app.

  12. In Xcode’s console I saw this:

    2017-08-18 09:56:25.339820+0100 MyFrameworkClient[62436:8801877] Hello Cruel World!

    -

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Ahhh...yes I see that I can create my own objective C framework to work with my swift framework. Cool...

What I was shooting for is leveraging someone else's third party framework (either wrapping it or exposing some of its functionality). It sounds like I should be able to embed the third party asset into my own objective C wrapper. I originally tried including the third party framework in my swift framework and even got it to build but the code would crash (I expect a dylib error or some bundle I did not include).

Thanks