Using Swift Framework inside Objective C Project - ios

I have an Swift Framework which works perfectly inside Swift Projects. Now I am trying to use it inside of Objective-C project.
Iv'e Change the Class to looks like:
#objc public class Test : NSObject {}
I imported the framework to the Objective-C project, added it to the Embedded Binaries and to the Linked Frameworks and Libraries.
In the ViewController.m I imported the framework like this:
#import <SwiftFramework/SwiftFramework-Swift.h>
And I try to create instance of type Test:
Test* test = [[Test alloc] init];
Test is recognize but when I try to build it to iPhone it's failed with the reason of:
Undefined symbols for architecture arm64: "_OBJC_CLASS_$__TtC14SwiftFramework4Test", referenced from:
And if I build it to a simulator it failed with the reason of:
Undefined symbols for architecture i386: "_OBJC_CLASS_$__TtC14SwiftFramework4Test", referenced from:
I've tried to add the i386 and arm64 to the Valid Architectures,
I've tried to change the Build Active Architecture Only to No.
I've found a lot of solution which did not help me solve the issue.
I'll appreciate any help, Thank you.
SOLVED:
Build Setting -> Build Settings -> Always Embed Swift Standard Libraries -> YES
I updated the framework and the Objective-C project.

Related

Xcode: Undefined symbols for architecture arm64:"_OBJC_CLASS_$_ATTrackingManager"

I'm exporting a project from Unity to IOS (Xcode), and when building I'm getting this error in Xcode. What should I do?
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_ATTrackingManager", referenced from:
objc-class-ref in libGameAnalytics.a(GADevice.o)
I'm not a "unity" guy, but from the looks of the error message you do not have a symbol included in your project by that name ... looks like it's trying to find the symbol from a static library named "libGameAnalytics" and looking for the GADevice object file (notice the "dot 'O'). If you are setting up a regular Xcode/iOS project then I'd recommend you use the corresponding "native" Swift/Objective-C Frameworks, static libraries, Cocoapods, or import source files.
Try making that replacement from Xcode's project file, and see if your error goes away ... it's at least a place to begin investigation, and might provide additional insight to the problem.

iOS import custom framework into project

I've developped a framework which I want to use in my projects. Everything went right until I tried to build my project. Here the error description :
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_ClassInFramework", referenced from:
objc-class-ref in ClassInMyProject.o
ld: symbol(s) not found for architecture arm64
My Architectures build settings are :
$(ARCHS_STANDARD)
and arm64 armv7 armv7s for valid arch
(same settings in my project and my framework, there are all default settings)
I can import myframework and build with no issue, but I get that error when I tried to use a class.
I'm on XCode 8.2.1, my Framework is a Cococa touch Framework, written in Objective-C, my project is written in Swift 3.0
I imported my framework by copying the output from Products and added it in Linked Frameworks and Libraries in my project
I've tried several different settings but none of them work.
You should remove the project folder from Xcode Drived Date and restart your Xcode then clean your project and run it.
I didn't solve my issue but I've managed to do something similar.
Instead of creating a Cocoa touch framework I created a Cocoa Touch static library and it worked.
I build my library,
I get the products (*.h and .a files), copy them in my project,
I add the lib.a in Linked Frameworks and libraries,
I create the Bridging Header and #import my "customlib.h",
Magic ! It works I can use my class.

Global Function from framework gives Undefined symbols linker error

I am trying to use a framework in my app (CoreBitcoin). Followed the build instructions from the README and copied the framework directory into my project. I also linked it in the Build Phases -> Link Binary With Libraries.
Now the code compiles and works
#import <CoreBitcoin/CoreBitcoin.h>
// I can instantiate class objects and use functions such as
BTCKey *newKey = [[BTCKey alloc] init];
[newKey setPublicKey: nil];
But if I try to use any global function such as
BTCDataFromBase58(#"anystring");
The linker throws an error:
Undefined symbols for architecture i386:
"BTCDataFromBase58(NSString*)"
I have looked around and tried many solutions to fix this error: the framework is in my search paths, I disabled bitcode and fiddled a bunch with the project build settings, however, it is strange that the undefined symbols are specific to global functions.
I am using Xcode 7.2, and get the warning:
(CoreBitcoin library path) was built for newer iOS version (9.2) than being linked (7.1)

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_CMMotionManager", referenced from: objc-class-ref in GooglePlus(GPPSpamSignal.o)

Hello I have a project that some one has developed. It has G+, FB integration. When I get the project and try to run it, it gives me this error. How I can solve this? Please help me.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_CMMotionManager", referenced from:
objc-class-ref in GooglePlus(GPPSpamSignal.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thanks
Undefined symbols means usually that you are missing an import statement.
Looks like you are using
CMMotionManager is part of CoreMotion, so you might need to :
#import <CoreMotion/CoreMotion.h>
And verify that you have added CoreMotion to your project
As CMMotionManager is part of CoreMotion framework, simply include the framework in your build in Xcode in "target"'s Build Phases: "link with": add "+" "CoreMotion.framework"
I managed to invoke this unholy error by simply adding the .h and .m files to the project.
I fixed this by removing them, and then right-clicking on the project, clicking New File, and choosing a new iOS Cocoa Touch class.
After that, I copied the relevant code into the respective .h and .m files. Doing it this way properly links the files
CMMotionManager is part of CoreMotion.framework.
In Xcode 11.3, TARGETS > Frameworks, Libraries, and Embedded Content > click the add button '+', add CoreMotion.framework.
The picture is in the below.
It appears that you are using GooglePlus SDK and the SDK is not supporting arm64 architecture. You need an updated SDK that supports arm64 architecture. Make sure you have latest copy.

Creating a framework with mixed Swift & Objective-C code

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.
To solve your project there's 2 things to check.
Do you have the correct "valid architecture" in your project
(1st picture below), and
Do you have a BridgingHeader properly
created for working with Swift and Obj-C in the same project (2nd
picture below)?

Resources