How to call an Objective-C singleton from Swift?

后端 未结 3 1930
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 07:48

I have an objective-C singleton as follows:

 @interface MyModel : NSObject
    + (MyModel*)   model;
    ...


        + (MyModel*) model 
        {
                     


        
3条回答
  •  长发绾君心
    2021-02-20 08:15

    If the Swift compiler mistakenly identifies a method as a class factory method, you can use the NS_SWIFT_NAME macro, passing the Swift signature of the method to have it imported correctly. For example:

    + (id)recordWithQuality:(double)quality NS_SWIFT_NAME(record(quality:));
    

    so,your method should be this:

    + (MyModel*)model NS_SWIFT_NAME(log());
    

提交回复
热议问题