我的代码:
public protocol ApiRequestBaseObjProtocol {
var param:[String:Any] { get set }
var path:String {get}
}
extension ApiRequestBaseObjProtocol {
var param: [String : Any] {
get {
var key = "\(self.path)"
return (objc_getAssociatedObject(self, &key) as? [String : Any]) ?? [:]
}
set(newValue) {
var key = "\(self.path)"
objc_setAssociatedObject(self, &key, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
enum MeApi : ApiRequestBaseObjProtocol {
public var path: String {
return "test/api/xxx"
}
}
在参数 get{} 方法中:objc_getAssociatedObject(self, &key) 为 nil。我想知道为什么?谢谢你!!