How to create a Swift object in Objective-C? -
if define swift class this
@objc class cat { }
in swift can do
var c = cat()
but how make cat
instance in objective-c ?
subclassing nsobject
works because can "alloc-init" can achieve without subclassing objective-c class?
the direct way subclass cat
nsobject
. if can't that, need make class method or function returns cat
.
@objc class cat { class func create() -> cat { return cat() } } func createcat() -> cat { return cat() } cat *cat = [cat create]; cat *cat = createcat();
Comments
Post a Comment