【问题标题】:Method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C方法不能是 @objc 协议的成员,因为它的结果类型不能在 Objective-C 中表示
【发布时间】:2019-10-14 15:40:34
【问题描述】:

创建此方法时出现“方法不能成为 @objc 协议的成员,因为其结果类型无法在 Objective-C 中表示”错误

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

【问题讨论】:

标签: objective-c swift


【解决方案1】:

元组不能在 Obj-C 中表示,所以你不能让你的函数返回一个元组。创建一个 Obj-C 类型,它包含您要返回的两个字段并返回该类型而不是元组。

@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
}

【讨论】:

    猜你喜欢
    • 2018-09-08
    • 2016-06-22
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多