Просмотр исходного кода

Solve warnings for macOS target

onevcat 1 год назад
Родитель
Сommit
d4e29b458b

+ 14 - 10
Sources/Extensions/NSButton+Kingfisher.swift

@@ -54,7 +54,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         options: KingfisherOptionsInfo? = nil,
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
         return setImage(
         return setImage(
@@ -87,7 +87,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         options: KingfisherOptionsInfo? = nil,
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         return setImage(
         return setImage(
             with: resource?.convertToSource(),
             with: resource?.convertToSource(),
@@ -102,7 +102,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         parsedOptions: KingfisherParsedOptionsInfo,
         parsedOptions: KingfisherParsedOptionsInfo,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         var mutatingSelf = self
         var mutatingSelf = self
         guard let source = source else {
         guard let source = source else {
@@ -127,11 +127,13 @@ extension KingfisherWrapper where Base: NSButton {
         let task = KingfisherManager.shared.retrieveImage(
         let task = KingfisherManager.shared.retrieveImage(
             with: source,
             with: source,
             options: options,
             options: options,
-            downloadTaskUpdated: { mutatingSelf.imageTask = $0 },
+            downloadTaskUpdated: { task in
+                Task { @MainActor in mutatingSelf.imageTask = task }
+            },
             progressiveImageSetter: { self.base.image = $0 },
             progressiveImageSetter: { self.base.image = $0 },
             referenceTaskIdentifierChecker: { issuedIdentifier == self.taskIdentifier },
             referenceTaskIdentifierChecker: { issuedIdentifier == self.taskIdentifier },
             completionHandler: { result in
             completionHandler: { result in
-                CallbackQueue.mainCurrentOrAsync.execute {
+                CallbackQueueMain.currentOrAsync {
                     guard issuedIdentifier == self.taskIdentifier else {
                     guard issuedIdentifier == self.taskIdentifier else {
                         let reason: KingfisherError.ImageSettingErrorReason
                         let reason: KingfisherError.ImageSettingErrorReason
                         do {
                         do {
@@ -183,7 +185,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         options: KingfisherOptionsInfo? = nil,
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
         return setAlternateImage(
         return setAlternateImage(
@@ -216,7 +218,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         options: KingfisherOptionsInfo? = nil,
         options: KingfisherOptionsInfo? = nil,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         return setAlternateImage(
         return setAlternateImage(
             with: resource?.convertToSource(),
             with: resource?.convertToSource(),
@@ -231,7 +233,7 @@ extension KingfisherWrapper where Base: NSButton {
         placeholder: KFCrossPlatformImage? = nil,
         placeholder: KFCrossPlatformImage? = nil,
         parsedOptions: KingfisherParsedOptionsInfo,
         parsedOptions: KingfisherParsedOptionsInfo,
         progressBlock: DownloadProgressBlock? = nil,
         progressBlock: DownloadProgressBlock? = nil,
-        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
+        completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
     {
         var mutatingSelf = self
         var mutatingSelf = self
         guard let source = source else {
         guard let source = source else {
@@ -266,9 +268,11 @@ extension KingfisherWrapper where Base: NSButton {
         let task = KingfisherManager.shared.retrieveImage(
         let task = KingfisherManager.shared.retrieveImage(
             with: source,
             with: source,
             options: options,
             options: options,
-            downloadTaskUpdated: { mutatingSelf.alternateImageTask = $0 },
+            downloadTaskUpdated: { task in
+                Task { @MainActor in mutatingSelf.alternateImageTask = task }
+            },
             completionHandler: { result in
             completionHandler: { result in
-                CallbackQueue.mainCurrentOrAsync.execute {
+                CallbackQueueMain.currentOrAsync {
                     guard issuedIdentifier == self.alternateTaskIdentifier else {
                     guard issuedIdentifier == self.alternateTaskIdentifier else {
                         let reason: KingfisherError.ImageSettingErrorReason
                         let reason: KingfisherError.ImageSettingErrorReason
                         do {
                         do {

+ 3 - 0
Sources/General/Kingfisher.swift

@@ -34,6 +34,9 @@ public typealias KFCrossPlatformView        = NSView
 public typealias KFCrossPlatformColor       = NSColor
 public typealias KFCrossPlatformColor       = NSColor
 public typealias KFCrossPlatformImageView   = NSImageView
 public typealias KFCrossPlatformImageView   = NSImageView
 public typealias KFCrossPlatformButton      = NSButton
 public typealias KFCrossPlatformButton      = NSButton
+
+// `NSImage` is not yet Sendable. We have to assume it sendable to resolve warnings in Kingfisher.
+extension KFCrossPlatformImage: @unchecked Sendable { }
 #else // os(macOS)
 #else // os(macOS)
 import UIKit
 import UIKit
 public typealias KFCrossPlatformImage       = UIImage
 public typealias KFCrossPlatformImage       = UIImage

+ 6 - 6
Sources/Image/Image.swift

@@ -27,8 +27,8 @@
 
 
 #if os(macOS)
 #if os(macOS)
 import AppKit
 import AppKit
-private var imagesKey: Void?
-private var durationKey: Void?
+private let imagesKey = malloc(1)!
+private let durationKey = malloc(1)!
 #else
 #else
 import UIKit
 import UIKit
 import MobileCoreServices
 import MobileCoreServices
@@ -71,13 +71,13 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
     }
     }
     
     
     private(set) var images: [KFCrossPlatformImage]? {
     private(set) var images: [KFCrossPlatformImage]? {
-        get { return getAssociatedObject(base, &imagesKey) }
-        set { setRetainedAssociatedObject(base, &imagesKey, newValue) }
+        get { return getAssociatedObject(base, imagesKey) }
+        set { setRetainedAssociatedObject(base, imagesKey, newValue) }
     }
     }
     
     
     private(set) var duration: TimeInterval {
     private(set) var duration: TimeInterval {
-        get { return getAssociatedObject(base, &durationKey) ?? 0.0 }
-        set { setRetainedAssociatedObject(base, &durationKey, newValue) }
+        get { return getAssociatedObject(base, durationKey) ?? 0.0 }
+        set { setRetainedAssociatedObject(base, durationKey, newValue) }
     }
     }
     
     
     var size: CGSize {
     var size: CGSize {

+ 10 - 6
Sources/Utility/DisplayLink.swift

@@ -76,19 +76,27 @@ extension CADisplayLink: DisplayLinkCompatible, @unchecked Sendable {
 }
 }
 #endif
 #endif
 
 
-final class DisplayLink: DisplayLinkCompatible {
+final class DisplayLink: DisplayLinkCompatible, @unchecked Sendable {
     private var link: CVDisplayLink?
     private var link: CVDisplayLink?
     private var target: Any?
     private var target: Any?
     private var selector: Selector?
     private var selector: Selector?
     
     
     private var schedulers: [RunLoop: [RunLoop.Mode]] = [:]
     private var schedulers: [RunLoop: [RunLoop.Mode]] = [:]
     
     
+    var preferredFramesPerSecond: NSInteger = 0
+    var timestamp: CFTimeInterval = 0
+    var duration: CFTimeInterval = 0
+    
     init(target: Any, selector: Selector) {
     init(target: Any, selector: Selector) {
         self.target = target
         self.target = target
         self.selector = selector
         self.selector = selector
         CVDisplayLinkCreateWithActiveCGDisplays(&link)
         CVDisplayLinkCreateWithActiveCGDisplays(&link)
         if let link = link {
         if let link = link {
-            CVDisplayLinkSetOutputHandler(link, displayLinkCallback(_:inNow:inOutputTime:flagsIn:flagsOut:))
+            CVDisplayLinkSetOutputHandler(link) { displayLink, inNow, inOutputTime, flagsIn, flagsOut in
+                self.displayLinkCallback(
+                    displayLink, inNow: inNow, inOutputTime: inOutputTime, flagsIn: flagsIn, flagsOut: flagsOut
+                )
+            }
         }
         }
     }
     }
     
     
@@ -133,10 +141,6 @@ final class DisplayLink: DisplayLinkCompatible {
         }
         }
     }
     }
     
     
-    var preferredFramesPerSecond: NSInteger = 0
-    var timestamp: CFTimeInterval = 0
-    var duration: CFTimeInterval = 0
-    
     func add(to runLoop: RunLoop, forMode mode: RunLoop.Mode) {
     func add(to runLoop: RunLoop, forMode mode: RunLoop.Mode) {
         assert(runLoop == .main)
         assert(runLoop == .main)
         schedulers[runLoop, default: []].append(mode)
         schedulers[runLoop, default: []].append(mode)