以下代码无法为我编译:
import Foundation
@objc public protocol MyProtocol {
func protocolMethod(parameter: (String)) -> String
func anotherProtocolMethod() -> Int
}
class MyClass: NSObject {
var myValue = self.anotherProtocolMethod()
}
extension MyClass: MyProtocol {
func protocolMethod(parameter: (String)) -> String {
return ""
}
func anotherProtocolMethod() -> Int {
return 1
}
}
错误发生在 myValue 被分配的行上,它显示:错误:'NSObject -> () ->MyClass 没有成员 anotherProtocolMethod 类型的值
有没有办法在不将 myValue 移动到类扩展中的情况下完成这项工作?