The process for an app to include and use a Swift (or mixed framework) is detailed in this document. It specifically deals with the case of accessing a Swift only framework within an app (Swift or Objective C source files): search on "Importing External Frameworks". Essentially you should add "@import MyFramework;" to your Objective-C source files.
I did this, but no matter what I try, I cannot get this to work using Xcode 8.0:
- construct a Swift 3 only framework and add it to my app
- insure that the framework is in the link phase, and there is a dependency on it
- insure that "Defines Module" is enabled
- add a "@import MyFramework;" line to an Objective C .m file in the app
Build:
- the framework builds, I see the MyFramework-Swift.h file in the derived folder
- Objective C app files that have the @import MyFramework; generate errors: "Cannot access such and such a property on a forward class declaration."
No matter what I do - remove the derived folder, restart Xcode, jump up and down, and swear at my Mac - nothing helps.
Note that the "MyFramework-Swift.h" file is constructed - I can see it in the app's derived folder, where the Frameworks are build.
After hours and hours of banging my head, I finally just copied that header file into my app's directory, with all the other .h files, and added a line to my source "#include "MyFramework-Swift.h" under the @import MyFramework; line.
Finally - now I can build my app!
Unless someone can point out my error I'll be stuck running some script to copy that file after the framework builds, but before the app source is compiled. I must be doing something wrong, but no amount of googling has helped.
I would be extremely thankful for anyone who can shed some light on this!
I found the cause - the SWIFT_INSTALL_OBJC_HEADER setting was NO in the module. Since the module itself has no objective C in it, I misunderstood the purpose of this flag, thinking it was so that module internal Objective C would have use of the header. Since the default for this flag is YES, most other module developers would not have had this issue.