1

I have a singleton class and a function that use one of its shared properties. I am getting this error:

"Method can not be marked as @objc because the type of the parameter 2 can not be represented in Objective-C".

My singleton class:

public class MessageManager {
    public static var shared = MessageManager()
    private init () {}
    
    public enum messageFlag: String {  // this is the enum causing the error when used 
        case sensitive
    }
    
}

The error is happening when i use the enum from singleton:

@objc func checkMessage (_sender: UIBarButtonItem? , messageId: String? = nil , flag: MessageManager.messageFlag ) {
    
}

I have seen other people's solutions like the use of NSObject in class but still not working. Any fix for this?

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33

1 Answers1

2

The enum is the problem. As suggested by @Cristik, you need to declare your enum as @obj as well, and in order to do that it needs to be an integer type.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • the issue i need the enum to be string based and not int based – Humble Fool Sep 02 '21 at 19:46
  • Yeah... no. You can't. Objective-C enums are **only** integer types. That' all the language understands. For Objective-C/Swift interoperability you have to limit yourself to the types that Objective-C understands. – Duncan C Sep 02 '21 at 20:22