Parcourir la source

Isolate the Source Identifier

And remove unnecessary assertion
onevcat il y a 1 an
Parent
commit
b2dc9fa0a5

+ 1 - 0
Sources/Extensions/CPListItem+Kingfisher.swift

@@ -29,6 +29,7 @@
 import CarPlay
 import CarPlay
 
 
 @available(iOS 14.0, *)
 @available(iOS 14.0, *)
+@MainActor
 extension KingfisherWrapper where Base: CPListItem {
 extension KingfisherWrapper where Base: CPListItem {
     
     
     // MARK: Setting Image
     // MARK: Setting Image

+ 4 - 2
Sources/Extensions/NSTextAttachment+Kingfisher.swift

@@ -32,6 +32,7 @@ import AppKit
 import UIKit
 import UIKit
 #endif
 #endif
 
 
+@MainActor
 extension KingfisherWrapper where Base: NSTextAttachment {
 extension KingfisherWrapper where Base: NSTextAttachment {
 
 
     // MARK: Setting Image
     // MARK: Setting Image
@@ -244,10 +245,11 @@ extension KingfisherWrapper where Base: NSTextAttachment {
     }
     }
 }
 }
 
 
-private var taskIdentifierKey: Void?
-private var imageTaskKey: Void?
+@MainActor private var taskIdentifierKey: Void?
+@MainActor private var imageTaskKey: Void?
 
 
 // MARK: Properties
 // MARK: Properties
+@MainActor
 extension KingfisherWrapper where Base: NSTextAttachment {
 extension KingfisherWrapper where Base: NSTextAttachment {
 
 
     public private(set) var taskIdentifier: Source.Identifier.Value? {
     public private(set) var taskIdentifier: Source.Identifier.Value? {

+ 1 - 0
Sources/Extensions/UIButton+Kingfisher.swift

@@ -29,6 +29,7 @@
 #if canImport(UIKit)
 #if canImport(UIKit)
 import UIKit
 import UIKit
 
 
+@MainActor
 extension KingfisherWrapper where Base: UIButton {
 extension KingfisherWrapper where Base: UIButton {
 
 
     // MARK: Setting Image
     // MARK: Setting Image

+ 3 - 3
Sources/General/ImageSource/Source.swift

@@ -43,11 +43,11 @@ public enum Source {
 
 
         /// The underlying value type of source identifier.
         /// The underlying value type of source identifier.
         public typealias Value = UInt
         public typealias Value = UInt
-        static private(set) var current: Value = 0
+        
+        @MainActor static private(set) var current: Value = 0
         
         
         // Not thread safe. Expected to be always called on the main thread.
         // Not thread safe. Expected to be always called on the main thread.
-        static func next() -> Value {
-            assert(Thread.isMainThread, "The identifier `next()` should only be called on main thread.")
+        @MainActor static func next() -> Value {
             current += 1
             current += 1
             return current
             return current
         }
         }