importing swift framework into a objective-c project
To access a swift class in objc, that is not inherited from NSObject you need to:
@objc public class VeediUtils
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
How to use Swift classes in Objective-C files in framework?
FYI the solution to this issue is just changing
#import "ProjectName-Swift.h"
into
#import "ProjectName/ProjectName-Swift.h"
Using a Objective C framework inside a Xcode Swift Project
The most easy way without digging to deep into settings is..
In your Swift project create one Objective-C Class (
.m
+.h
) file, the naming is not important. This file will be needed anyway so you can code more in objective-c for your project.When you are asked to
generate Bridging Header
, say yes.In the generated
Projectname-Bridging-Header.h
(not your own created file)
place your#import <SDF/SDF.h>
rule.Compile once.
Start programming in swift with your ObjC stuff.
Alternative: go into your target settings or project settings and search for "bridging" and change the parameters as you need.
There is (A) one way bridging to swift and (B) one way auto generated bridging into objective-c. Both name conventions can be edited but only one Projectname-Bridging-Header.h
will be visible in your project file tree. The other one Projectname-Swift.h
is repeatedly generated from Xcode for you. If you try to expose functions from Swift to Objective-C, this "invisible" header file needs to be imported as well, but in the Objective-C file you need it via #import "Projectname-Swift.h"
.
Related Topics
iOS 7 Device Token Is Different for Same Device
Change the Alpha Value of the Navigation Bar
Will Appstore Reviewers Allow Us to Use Dynamic Library in iOS8
How to Receive Push Notifications of an Other App
Collectionview with the Horizontal Scroll with Mulitple Section
Xcode 11.4. Navigation's Title Color Gone Black from Storyboard
How to Animate a Uiview with Constraints in Swift
It Gives Errors When Using Swift Static Library with Objective-C Project
Xcode 8 with Mixed Swift and Objective-C Project Generated "Modulename-Swift.H" Header Not Found
Has Anyone Found a Good Way of Using the New iOS5 Keyboard Events
Is It Safe to Delete SQLite's Wal File
How to List (Almost) All Emojis in Swift for iOS 8 Without Using Any Form of Lookup Tables
iPad - Parsing an Extremely Huge JSON - File (Between 50 and 100 Mb)
Perform UI Changes on Main Thread Using Dispatch_Async or Performselectoronmainthread