Explorar o código

fix Any? cast to protocol always nil in ios 13

wangwenyu %!s(int64=2) %!d(string=hai) anos
pai
achega
738629cdc8
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      Sources/Utility/Runtime.swift

+ 5 - 1
Sources/Utility/Runtime.swift

@@ -27,7 +27,11 @@
 import Foundation
 
 func getAssociatedObject<T>(_ object: Any, _ key: UnsafeRawPointer) -> T? {
-    return objc_getAssociatedObject(object, key) as? T
+    if #available(iOS 14, macOS 11, *) {
+        return objc_getAssociatedObject(object, key) as? T
+    } else {
+        return objc_getAssociatedObject(object, key) as AnyObject as? T
+    }
 }
 
 func setRetainedAssociatedObject<T>(_ object: Any, _ key: UnsafeRawPointer, _ value: T) {