Question or problem in the Swift programming language:
I’d created a test project to try Swift. But I’ve stuck on importing Swift class into Objective-C class. Project name is “TestSwift1”. And I have set Defines Module in Packaging to YES. XCode-Beta3
I have next code:
//swift SwtClass.swift import Foundation class SwtClass { var title = "" } //Objective-C ObjClass.h @interface ObjClass : NSObject @property (nonatomic, strong) NSString* title; @end //Objective-c ObjClass.m #import #import "ObjClass.h" #import @implementation ObjClass - (void)doSomething { SwtClass* b; // Error: "Use of undeclared identifier 'SwtClass'" // Error: "Use of undeclared identifier 'b'" NSLog(@"something is done"); } @end
How to solve the problem:
While writing this question I’ve found solution. And as always it was very simple but took a while maybe this will save somebody a couple of minutes.
To use Swift class(that is not a subclass of NSObject) in Objective-C don’t forget to mark it with @objc as it said here “Using Swift from Objective-C”. My Swift class had to look like this:
//swift SwtClass.swift import Foundation @objc class SwtClass { var title = "" }