Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an Obj-C sub-project in a Swift application

My team has a few full Obj-C libraries we like te reuse in our projects. To do so, we usually set up a git submodule, and then add it to the xcode project as a sub-project (Using target dependency, link binary with library and updating the User Header Search Paths)

So far it's only been done in full Obj-C projects, and I'm now trying to use it in a Swift project but with very little success so far. I tried to add the briding-header file, referenced it in the project and filled it like so :

#import "MyLibraryHeader.h"

With the target header being in the User Header Search Paths.

It lets me build, but when using it in my Swift files:

    let test = MyLib();
    let secondTest = MyLib.classMethod1("some_arguments");

I get an EXC_BAD_INSTRUCTION on secondTest, and the following logs in the debugger:

(lldb) po test
error: <EXPR>:1:1: error: use of unresolved identifier 'test'

(lldb) po secondTest
error: Error in auto-import:
failed to get module 'MyProject' from AST context:
/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h:12:9: error: 'MyLibraryHeader.h' file not found
#import "MyLibraryHeader.h"
        ^
failed to import bridging header '/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h'

Found the following question with no answer : Xcode 6 crashing when using Objective-C subproject inside Swift

Any help would be appreciated.

like image 502
Nerkatel Avatar asked Sep 25 '14 17:09

Nerkatel


1 Answers

I followed the HockeyApp tutorial that can be found here: http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/integrate-hockeyapp-for-ios-as-a-subproject

In the end, I was on the right tracks but messed up the Header Search Paths:

  1. Add subproject xcodeproj to the workspace
  2. On the main project : Link binary with library, and add the subproject product library (Bonus points : add it as a target dependency too)
  3. Update Header Search Paths (not User Header Search Paths) accordingly
  4. Import your Library.h in the main project Bridging-Header.h file
like image 172
Nerkatel Avatar answered Nov 07 '22 21:11

Nerkatel