2014/11/26

Using Swift's class in Objective-C project

Very tired to find the way to use a Swift’s class in an Objective-C project.
There were two points I took much time to find the answer.

1) How to create ‘<project name>-Swift.h’ file
My Xcode did not make this file when I added or created a Swift file in an Objective-C project. So I added it by myself, but it did not work.

I found this file does not appear in Xcode much later.


2) Use of undeclared identifier error
MySwiftClass *object = [MySwiftClass new];
This code should make an object from Swift class, but an error message
Use of undeclared identifier ‘MySwiftClass’
appeared.

MySwiftClass is a subclass of NSObject, and I added @objc just in case but the error did not disappear. This class had worked as I expected in a Swift project.

Finally this page helped me :
ios - Including Swift files in Objective-C - Stack Overflow

I had to added ‘public’ just before a declaration of the Swift class.
Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示