简体   繁体   中英

Method cannot be a member of an @objc protocol after i remove tuple

I am trying to use Swift protocol in Objective-C.

Firstly it was using tuple like this:

protocol Validation {
    func validate(value:String?) -> (Bool, ValidationErrorType)
}

and because tuples are not suitable for Objective-C i decide to use Dictionary for that.

@objc protocol Validation {
    func validate(value:String?) -> [NSNumber : ValidationErrorType]
}

And the result is :

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

Could you please share you're opinion about what i am doing wrong ?

The method have ValidationErrorType as a result with Dictionary , and that's I think preventing you from bridging the protocol. To solve the problem you have to make it objc compatible or change the return value to directly NSDictionary like this.

@objc protocol Validation {
    func validate(value:String?) -> NSDictionary
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM