How to create a Swift object in Objective-C?

后端 未结 3 2057
时光说笑
时光说笑 2021-01-06 05:32

If you define a swift class like this

@objc class Cat {

}

In swift you can just do

var c = Cat()

But how

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 06:25

    In modern objective-c you can call functions like they were properties:

    Swift:

    class func create() -> Cat {
        return Cat()
    }
    

    Obj-c:

    Cat *cat = Cat.create;
    

提交回复
热议问题