When I've added Swift class to Objective-C project it was not included to autogenerated header for swift.
My steps was as following:
- Created single view Objective C project with name "SwiftTest"
- Build Setting -> Packaging -> Defines Module set to "YES"
- Product Name (and Product Module Name) was not changes so it was "SwiftTest"
- Added Swift file SwiftInObjc.swift with single class:
import Foundation
class SwiftInObjc : NSObject{
func printHello(){
println("Hello")
}
}
- In ViewController class included header and declared swift object:
#import "SwiftTest-Swift.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SwiftInObjc * swiftObj;
}
After that project can't be build because of error:
Use of undeclared identifier "SwiftInObjc"
Header file "SwiftTest-Swift.h" has been created in derived data as expected, but it doesn't contain my swift class.
Note: My case is similar to this question but my class was subclassed from NSObject so it must be another reason. (also I've tried pure Swift class:
import Foundation
@objc class SwiftInObjc {
class func newInstance() -> SwiftInObjc {
return SwiftInObjc()
}
func hello() {
println("hello")
}
}
but it doesn't help, I still have same error)