3

I have a project with mixed code (objective-c and Swift) that I need to package as a framework. It also uses some external frameworks.

My umbrella header has many imports to different headers of the frameworks I use, as well as to the objective-c source code in my project (so that it's accessible by the Swift code). I also have a swift file, e.g. MyFramework.swift, that has some code that I'd like to expose to users of the framework.

The framework compiles, however, when I try to use it in another Swift project, I cannot access the contents of MyFramework.swift. That is the case even though the file exists (with the Swift source code) in the framework product!

Yet, I am able to access the objective-c code from the public headers. So I tried to write the code in MyFramework.swift in objective-c instead (MyFramework.h & MyFramework.m), because I thought it might be a problem exposing code in both objective-c and swift (though from what I read - it shouldn't be). That did the trick in terms of accessing the objects inside this class, but then I got a linker error:

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MyObject", referenced from: __TZFC12TestFW6MyObject20testfMS0_FCSo16UIViewControllerT_ in ViewController.o ld: symbol(s) not found for architecture x86_64

This actually happens for every public swift class I try to reference. I made sure these files exist in the "Compile Sources" list under Build Phases of the project settings, so that's not the problem.

I'm pretty clueless. Any ideas? Thanks.

E.K.
  • 321
  • 1
  • 11
  • did you find any solution to it? – Saty Apr 08 '16 at 13:19
  • Nope. I ended up creating two separate frameworks - one for Swift users and one for obj-c users. Gave up for now on creating one f/w for both. – E.K. May 23 '16 at 20:59

1 Answers1

0

To solve your project there's 2 things to check.

  1. Do you have the correct "valid architecture" in your project (1st picture below), and
  2. Do you have a BridgingHeader properly created for working with Swift and Obj-C in the same project (2nd picture below)?

Project Settings - Valid Architecture

Swift Compiler - Bridging Header

Larry B
  • 193
  • 11
  • The first setting you mentioned was already set correctly. I indeed was missing the bridging header in my test project, but adding it didn't help either. Still getting the linker error: Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_MyObject", referenced from: ... And still the swift code is not exposed to the project, this is only when using an objective-c header. – E.K. Aug 14 '15 at 08:52
  • @Pintouch posted this note: To access a Swift class in Objective-C, just add @objc(MyClass) in your Swift Class and it will be available in Objective-C files. http://stackoverflow.com/questions/26417735/build-a-library-for-swift-and-objective-c – Larry B Aug 14 '15 at 15:26
  • 1
    @E.K. There is no such thing as a bridging header in a swift framework, but there is an umbrella header, have a look here for more informations : http://stackoverflow.com/questions/31238761/what-is-an-umbrella-header – n3wbie Mar 14 '17 at 15:51