How do I create a Swift object in Objective-C?
3 answers
The most direct way is to subclass Cat
from NSObject
. If you cannot do this, you will need to create a class method or function that returns Cat
.
@objc class Cat {
class func create() -> Cat {
return Cat()
}
}
func CreateCat() -> Cat {
return Cat()
}
Cat *cat = [Cat create];
Cat *cat = CreateCat();
+2
source to share