0

I just created a framework in swift, and its working fine in swift project but in objective c I am getting errors like Undefined symbols for architecture armv7:. I just checked the available architectures using lipo -info, its showing both simulator and device architectures. Also I referred this link but no use. Attached image also. I'll appreciate any help, Thank you.

6
  • how have you added your library to your project? Commented Dec 10, 2018 at 7:42
  • Actually I added framework in extensions Using drag and drop. Commented Dec 10, 2018 at 7:50
  • Can you add image how to have added the framework? Commented Dec 10, 2018 at 9:29
  • I edited my question please check. Commented Dec 10, 2018 at 9:37
  • why haven't you added as embedded binary? Commented Dec 10, 2018 at 9:41

2 Answers 2

1

Here below is to do list in your Framework.

Swift classes usage in Objective C classes

  • Use Open Keyword before class name in Swift
  • Use @objc Keyword before Open Keyword of Swift class
  • Import all header of objective c classes in Umbrella file YourProject.h those are consuming Swift Classes.
  • Use #import in Objective c

I followed Apple Mix and Match approach. Hope this will help. Thanks

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for your response, I can able to access the classes of swift framework. I am not getting any errors like no such modules found. Issue related to architectures if I am not wrong.
Have you added your swift framework into Embedded section in App target?
Yes, I added in embedded section.
I don't know what exactly you did wrong but the error "Undefined symbols for architecture armv7" related to Library built for another architecture like i386, Like you built library for Simulator and running on your device, It should be same
Available architectures are i386, x86_64, armv7, arm64. Which means it works for both device and simulator.
|
0

To access a swift class in objc, that is not inherited from NSObject you need to:

@objc public class yourUtils

A Swift class or protocol must be marked with the @objc attribute to be accessible and usable in Objective-C. This attribute tells the compiler that this piece of Swift code can be accessed from Objective-C. If your Swift class is a descendant of an Objective-C class, the compiler automatically adds the @objc attribute for you.

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

1 Comment

Thanks for your response, actually I tried to add that in framework project like @objc public class Test : NSObject {}. After that I am getting error like duplicate interface definition for class and showing methods in my framework-swift.h file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.