Reed
Reed

Reputation: 1002

Method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C

I am getting "Method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C" error while making this method

 @objc public protocol ShareSecurityQuestionProtocol {
 func setResultofSecurityQuestion(valueSent: [NSMutableDictionary]) -> (success: Bool, error:  NSString)
 }

Upvotes: 0

Views: 1535

Answers (1)

David Pasztor
David Pasztor

Reputation: 54785

Tuples cannot be represented in Obj-C, so you cannot make your function return a tuple. Create an Obj-C type that holds both fields you want to return and return that type instead of a tuple.

@objc public class ShareSecurityQuestionResult: NSObject {
    let success: Bool
    let error: String

    init(success: Bool, error: String) {
        self.success = success
        self.error = error
    }
}

@objc public protocol ShareSecurityQuestionProtocol {
    func setResultofSecurityQuestion(valueSent: [NSMutableDictionary]) -> ShareSecurityQuestionResult
}

Upvotes: 2

Related Questions