1

I'm trying to import SKTUtils - which is a set of swift files - into an Objective-C project. As far as I know it would be enough to do this way:

#import "ProjectName-Swift.h"

But the problem is that SKTUtils is not a project, but rather a directory with a set of swift classes. I tried to import the files this way:

#import "Vector3-Swift.h"
#import "CGFloat+Extensions-Swift.h"
.... etcetera ....

But without success. I've also set to yes the define modules option inside the project's build setting but still nothing to do.

Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187

1 Answers1

-1

I have just tried to import SKTUtils in blank Objective-C Xcode project.

Looks like you are missing the following part of requirement for correct bridging:

You need to import ProjectName-Swift.h. Note that it's the project name - the other answers make the mistake of using the class name.

This single file is an autogenerated header that defines Objective-C interfaces for all Swift classes in your project that are either annotated @objc or inherit from NSObject.

taken from How to import Swift code to Objective-C.

For example in my test project my Project-Swift.h does contain imports of SKTUtils's extensions of SKAction because they are Objective-C-based classes of SpriteKit but some other stuff is not Objective-C friendly that's why you cannot access it because it is just not generated in -Swift.h file.

Another example is that I start seeing SKTAudio class in my Objective-C code if I make it a subclass of NSObject:

 @objc public class SKTAudio: NSObject {
Community
  • 1
  • 1
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129