How to call an Objective C class method in Swift

后端 未结 2 1138
独厮守ぢ
独厮守ぢ 2020-12-29 05:42

On my Objective-C header, I have the following class method declaration:

@interface WXMediaMessage : NSObject

    +(WXMediaMessage *) message;
2条回答
  •  独厮守ぢ
    2020-12-29 05:59

    The problem is the name. Swift does not import factory constructors. It detects these by noticing that the name is the same as the end of the class name.

    Change the message method name to something like singletonMessage and all will be well.

    If the name is message, you will see this:

    enter image description here

    But if I change the name to, say, messager, it compiles just fine.

    For an analogy, try this:

    var thing : HeyHo = HeyHo.ho()
    

    You will get the same error message.

提交回复
热议问题