Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swift library in an Objective-C project

I am working in an Objective-C, iOS project, I used danielgindi Charts library which is a Swift library. I downloaded it using Cocoapods.

I am trying to import the library files into my Objective-C files using 'projectName-Swift.h' as mentioned in this question but I faced an error:

'projectName-Swift.h' file not found

like image 213
Ahd Radwan Avatar asked May 28 '16 19:05

Ahd Radwan


People also ask

Does SwiftUI work Objective-C?

You can use it in any way you would use a UIViewController. Takeaway: By depending on UIHostingController and the interoperability of Swift and Objective-C programming languages, you can use SwiftUI framework from within your Objective-C legacy code.

Is Swift interoperable with Objective-C?

Swift has its own runtime, but it also has access to Objective-C runtime, and also access to C . Having access to those runtimes makes the interoperability between Swift and Objective-C easier to bridge.

Should I use Objective-C or Swift?

Objective-C has a superior runtime compared to Swift. It's probably going to be several years before Swift can catch up. If you're using powerful SDKs, Objective-C is also your best option here as well. I'd still recommend that new developers start off learning Swift.


2 Answers

If you have installed Swift library using cocoapods

To import Library in Objective C Code Use in Objective C

@import frameworkname;

In Swift

@import frameworkname
like image 91
Vinay Krishna Gupta Avatar answered Oct 02 '22 23:10

Vinay Krishna Gupta


If your using cocoa pods try to make sure you have use_frameworks! in your cocoa pods pod file, otherwise the Swift Framework wont work. Also look at this for any other issues that may pop up: link

like image 21
GlorySaber Avatar answered Oct 02 '22 23:10

GlorySaber