Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Swift classes in Objective-C files in framework?

I build framework, which has both Obj-C and Swift file. I need to import Swift file into Obj-C file using:

#import "ProjectName-Swift.h"

All Build settings are default, despite Defines module set to YES, Obj-C Generated Interface Header Name to $(PROJECT_NAME)-Swift.h and Always embed Swift Standard Libraries to YES (for both project and target).

Unfortunately I have error:

'ProjectName-Swift.h' file not found

when I build the project. How should I cope with importing Swift file into Obj-C?

I need to import Swift to Obj-C, not the other way.

like image 294
emil Avatar asked Dec 02 '25 10:12

emil


2 Answers

FYI the solution to this issue is just changing

#import "ProjectName-Swift.h"

into

#import "ProjectName/ProjectName-Swift.h"
like image 145
emil Avatar answered Dec 05 '25 02:12

emil


Just to add to the given answers.

Make sure your swift class is like this..

@objcMembers class SomeClass: NSObject {
  //Whatever you wish
}

This @objcMembers does the magic.

This is important since your objects need to be compiled into objc objects.

like image 41
GyroCocoa Avatar answered Dec 05 '25 01:12

GyroCocoa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!