Here's my sample project: https://github.com/Tj3n/TestProject
I'm trying to create a Swift framework to use in an Objective-C app, build works fine, configuration all keep to default, added the framework in the app, imported ok, but I cannot access the class written in Swift, which already marked with @objc
and public
, not sure if anyone have an idea where I did wrong
Framework:
@objc(TVNFoo) @objcMembers public class Foo: NSObject {
public static let shared = Foo()
public func foo() {
print("foo")
}
}
App:
@import TestFramework;
[TVNFoo shared]; // Use of undeclared identifier 'TVNFoo'
Edit:
By default Defines Module
and Build Libraries for Distribution
are set to Yes
Finally found the fix, for some reason the build setting SWIFT_INSTALL_OBJC_HEADER
is responsible for copying the generated header to the built framework, but by default it's being set to No
. Change to Yes
and it can find the symbols now.