Oleg Gordiichuk Oleg Gordiichuk - 1 year ago 135
iOS Question

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:

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

and because tuples are not suitable for Objective-C i decide to use
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 ?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download