Closed WilsonScott closed 1 year ago
extension DownloadTask{
static var TYPE_KEY: Void?
var platform_type: String {
get {
objc_getAssociatedObject(self, &Self.TYPE_KEY) as? String ?? ""
}
set {
objc_setAssociatedObject(self, &Self.TYPE_KEY, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
你关联对象没用好
我尝试 extension DownloadTask{ var platform_type: String { get { objc_getAssociatedObject(self, &Self.TYPE_KEY) as? String ?? "" } set { objc_setAssociatedObject(self, &Self.TYPE_KEY, newValue, .OBJC_ASSOCIATION_ASSIGN) } } }
结果在sessionManager.tasks 里边拿不到每个task的platform_type