Yang Chao 2 лет назад
Родитель
Сommit
d3a233773f
1 измененных файлов с 9 добавлено и 3 удалено
  1. 9 3
      Sources/Utility/DisplayLink.swift

+ 9 - 3
Sources/Utility/DisplayLink.swift

@@ -24,7 +24,8 @@
 //  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 //  THE SOFTWARE.
 
-#if !os(macOS)
+#if !os(watchOS)
+#if canImport(UIKit)
 import UIKit
 #else
 import AppKit
@@ -45,7 +46,6 @@ protocol DisplayLinkCompatible: AnyObject {
 }
 
 #if !os(macOS)
-
 extension UIView {
     func compatibleDisplayLink(target: Any, selector: Selector) -> DisplayLinkCompatible {
         return CADisplayLink(target: target, selector: selector)
@@ -55,21 +55,26 @@ extension UIView {
 extension CADisplayLink: DisplayLinkCompatible {}
 
 #else
-
 extension NSView {
     func compatibleDisplayLink(target: Any, selector: Selector) -> DisplayLinkCompatible {
+#if swift(>=5.9) // macOS 14 SDK is included in Xcode 15, which comes with swift 5.9. Add this check to make old compilers happy.
         if #available(macOS 14.0, *) {
             return displayLink(target: target, selector: selector)
         } else {
             return DisplayLink(target: target, selector: selector)
         }
+#else
+        return DisplayLink(target: target, selector: selector)
+#endif
     }
 }
 
+#if swift(>=5.9)
 @available(macOS 14.0, *)
 extension CADisplayLink: DisplayLinkCompatible {
     var preferredFramesPerSecond: NSInteger { return 0 }
 }
+#endif
 
 class DisplayLink: DisplayLinkCompatible {
     private var link: CVDisplayLink?
@@ -155,3 +160,4 @@ class DisplayLink: DisplayLinkCompatible {
     }
 }
 #endif
+#endif