Pārlūkot izejas kodu

Merge pull request #2182 from wy-time/fix

fix Any? cast to protocol always nil in ios 13
Wei Wang 2 gadi atpakaļ
vecāks
revīzija
ad51380c76
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  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, watchOS 7, tvOS 14, *) { // swift 5.3 fixed this issue (https://github.com/apple/swift/issues/46456)
+        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) {