We are developing two iOS applications (target 8.0) with Swift, and would like to have a following project structure
- Project for app 1 (App1)
- Project for app 2 (App2)
- Project for shared code (Common)
I understand that the correct solution with Swift would be to create the Common project as a framework, and import it to projects App1 and App2.
However, the Common project is mainly used to access our REST API with RestKit, which of course is an Objective-C library. If this was an application project, I could just add RestKit through CocoaPods, and import it in the bridging header, and everything works. However, with the framework project, after adding the RestKit pod and putting the import clause in the umbrella header, I get the following:
include of non-modular header inside framework module 'Common'
"Allow non-modular includes in Framework modules" is set to YES in the project settings, but does not seem to help.
Is this a problem with CocoaPods, RestKit or Xcode? In case the method described above is simply currently not possible, what might be the best way we could achieve sharing Swift code that uses Obj-C libraries?
I have tried the method described here: http://youku.io/questions/124456/obj-c-cocoapods-swift-framework, but did not have any success.
I have seen posts like this (Swift Framework with libxml), about making header files public, but I'm not exactly sure if this is the correct answer here, or how to proceed with doing it.
I have currently included the pod without "use_frameworks!" flag, as this has worked at least when using RestKit in Swift application projects. When using the flag, I get somewhat similar problems as described here (Fail to Import RestKit with Cocoapods Dynamic Frameworks). Could this be the solution once the RestKit team fixes the problem?
Edit:
I forked RestKit, included this pull request, and managed to get RestKit working with the use_frameworks! flag, which apparently was required for it to work as a part of a Swift framework. So original problem solved! However, I still have the problem that since umbrella header has the #include <RestKit/RestKit.h>
line, all the apps using the framework complain about this header not being found, unless I add the RestKit pod to all these projects as well (which is otherwise unnecessary). How could I avoid this? I tried setting umbrella header's scope from Public to Project, but this resulted in multiple build errors.