Przeglądaj źródła

Mark some types to sendable

onevcat 1 rok temu
rodzic
commit
fc805d1ac0

+ 1 - 1
Sources/Cache/CacheSerializer.swift

@@ -34,7 +34,7 @@ import UIKit
 
 
 /// A `CacheSerializer` is used to convert some data to an image object after retrieving it from disk storage,
 /// A `CacheSerializer` is used to convert some data to an image object after retrieving it from disk storage,
 /// and vice versa, to convert an image to a data object for storing it to the disk storage.
 /// and vice versa, to convert an image to a data object for storing it to the disk storage.
-public protocol CacheSerializer {
+public protocol CacheSerializer: Sendable {
     
     
     /// Retrieves the serialized data from a provided image and optional original data for caching to disk.
     /// Retrieves the serialized data from a provided image and optional original data for caching to disk.
     ///
     ///

+ 1 - 1
Sources/Cache/ImageCache.swift

@@ -49,7 +49,7 @@ extension Notification.Name {
 public let KingfisherDiskCacheCleanedHashKey = "com.onevcat.Kingfisher.cleanedHash"
 public let KingfisherDiskCacheCleanedHashKey = "com.onevcat.Kingfisher.cleanedHash"
 
 
 /// The type of cache for a cached image.
 /// The type of cache for a cached image.
-public enum CacheType {
+public enum CacheType: Sendable {
     /// The image is not yet cached when retrieving it.
     /// The image is not yet cached when retrieving it.
     ///
     ///
     /// This indicates that the image was recently downloaded or generated rather than being retrieved from either
     /// This indicates that the image was recently downloaded or generated rather than being retrieved from either

+ 1 - 1
Sources/General/ImageSource/ImageDataProvider.swift

@@ -30,7 +30,7 @@ import Foundation
 /// ``Source/provider(_:)`` source. Compared to ``Source/network(_:)`` member, it gives a chance
 /// ``Source/provider(_:)`` source. Compared to ``Source/network(_:)`` member, it gives a chance
 /// to load some image data in your own way, as long as you can provide the data
 /// to load some image data in your own way, as long as you can provide the data
 /// representation for the image.
 /// representation for the image.
-public protocol ImageDataProvider {
+public protocol ImageDataProvider: Sendable {
     
     
     /// The key used in cache.
     /// The key used in cache.
     var cacheKey: String { get }
     var cacheKey: String { get }

+ 1 - 1
Sources/General/ImageSource/Resource.swift

@@ -29,7 +29,7 @@ import Foundation
 /// Represents an image resource at a certain url and a given cache key.
 /// Represents an image resource at a certain url and a given cache key.
 /// Kingfisher will use a ``Resource`` to download a resource from network and cache it with the cache key when
 /// Kingfisher will use a ``Resource`` to download a resource from network and cache it with the cache key when
 /// using ``Source/network(_:)`` as its image setting source.
 /// using ``Source/network(_:)`` as its image setting source.
-public protocol Resource {
+public protocol Resource: Sendable {
     
     
     /// The key used in cache.
     /// The key used in cache.
     var cacheKey: String { get }
     var cacheKey: String { get }

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

@@ -36,7 +36,7 @@ import Foundation
 /// - `provider`: The target image should be provided in a data format. Normally, it can be an image
 /// - `provider`: The target image should be provided in a data format. Normally, it can be an image
 ///             from local storage or in any other encoding format (like Base64).
 ///             from local storage or in any other encoding format (like Base64).
 ///
 ///
-public enum Source {
+public enum Source: Sendable {
 
 
     /// Represents the source task identifier when setting an image to a view with extension methods.
     /// Represents the source task identifier when setting an image to a view with extension methods.
     public enum Identifier {
     public enum Identifier {

+ 5 - 6
Sources/General/KingfisherError.swift

@@ -44,7 +44,7 @@ public enum KingfisherError: Error {
     // MARK: Error Reason Types
     // MARK: Error Reason Types
 
 
     /// Represents the error reasons during the networking request phase.
     /// Represents the error reasons during the networking request phase.
-    public enum RequestErrorReason {
+    public enum RequestErrorReason: Sendable {
         
         
         /// The request is empty.
         /// The request is empty.
         ///
         ///
@@ -69,7 +69,7 @@ public enum KingfisherError: Error {
     }
     }
     
     
     /// Represents the error reason during networking response phase.
     /// Represents the error reason during networking response phase.
-    public enum ResponseErrorReason {
+    public enum ResponseErrorReason: Sendable {
         
         
         /// The response is not a valid URL response.
         /// The response is not a valid URL response.
         ///
         ///
@@ -126,7 +126,7 @@ public enum KingfisherError: Error {
     }
     }
     
     
     /// Represents the error reason during Kingfisher caching.
     /// Represents the error reason during Kingfisher caching.
-    public enum CacheErrorReason {
+    public enum CacheErrorReason: @unchecked Sendable {
         
         
         /// Cannot create a file enumerator for a certain disk URL.
         /// Cannot create a file enumerator for a certain disk URL.
         ///
         ///
@@ -237,9 +237,8 @@ public enum KingfisherError: Error {
         case diskStorageIsNotReady(cacheURL: URL)
         case diskStorageIsNotReady(cacheURL: URL)
     }
     }
     
     
-    
     /// Represents the error reason during image processing phase.
     /// Represents the error reason during image processing phase.
-    public enum ProcessorErrorReason {
+    public enum ProcessorErrorReason: Sendable {
         /// Image processing has failed, and there is no valid output image generated by the processor.
         /// Image processing has failed, and there is no valid output image generated by the processor.
         ///
         ///
         /// - Parameters:
         /// - Parameters:
@@ -251,7 +250,7 @@ public enum KingfisherError: Error {
     }
     }
 
 
     /// Represents the error reason during image setting in a view related class.
     /// Represents the error reason during image setting in a view related class.
-    public enum ImageSettingErrorReason {
+    public enum ImageSettingErrorReason: Sendable {
         
         
         /// The input resource is empty or `nil`.
         /// The input resource is empty or `nil`.
         ///
         ///

+ 3 - 3
Sources/General/KingfisherManager.swift

@@ -52,7 +52,7 @@ public typealias DownloadProgressBlock = ((_ receivedSize: Int64, _ totalSize: I
 ///
 ///
 /// This type encapsulates the outcome of an image retrieval operation performed by Kingfisher.
 /// This type encapsulates the outcome of an image retrieval operation performed by Kingfisher.
 /// It holds a successful result with the retrieved image.
 /// It holds a successful result with the retrieved image.
-public struct RetrieveImageResult {
+public struct RetrieveImageResult: Sendable {
     /// Retrieves the image object from this result.
     /// Retrieves the image object from this result.
     public let image: KFCrossPlatformImage
     public let image: KFCrossPlatformImage
 
 
@@ -79,7 +79,7 @@ public struct RetrieveImageResult {
     ///
     ///
     /// - Note: Retrieving this data can be a time-consuming operation, so it is advisable to store it if you need to 
     /// - Note: Retrieving this data can be a time-consuming operation, so it is advisable to store it if you need to 
     /// use it multiple times and avoid frequent calls to this method.
     /// use it multiple times and avoid frequent calls to this method.
-    public let data: () -> Data?
+    public let data: @Sendable () -> Data?
 }
 }
 
 
 /// A structure that stores related information about a ``KingfisherError``. It provides contextual information
 /// A structure that stores related information about a ``KingfisherError``. It provides contextual information
@@ -599,7 +599,7 @@ public class KingfisherManager {
                             cacheType: $0.cacheType,
                             cacheType: $0.cacheType,
                             source: source,
                             source: source,
                             originalSource: context.originalSource,
                             originalSource: context.originalSource,
-                            data: { options.cacheSerializer.data(with: image, original: nil) }
+                            data: { [image] in options.cacheSerializer.data(with: image, original: nil) }
                         )
                         )
                     }
                     }
                     completionHandler(value)
                     completionHandler(value)

+ 1 - 1
Sources/General/KingfisherOptionsInfo.swift

@@ -359,7 +359,7 @@ public enum KingfisherOptionsInfoItem {
 /// Each property in this type corresponds to a case member in ``KingfisherOptionsInfoItem``. When a
 /// Each property in this type corresponds to a case member in ``KingfisherOptionsInfoItem``. When a
 ///  ``KingfisherOptionsInfo`` is sent to Kingfisher-related methods, it will be parsed and converted to a
 ///  ``KingfisherOptionsInfo`` is sent to Kingfisher-related methods, it will be parsed and converted to a
 ///  ``KingfisherParsedOptionsInfo`` first before passing through the internal methods.
 ///  ``KingfisherParsedOptionsInfo`` first before passing through the internal methods.
-public struct KingfisherParsedOptionsInfo {
+public struct KingfisherParsedOptionsInfo: Sendable {
 
 
     public var targetCache: ImageCache? = nil
     public var targetCache: ImageCache? = nil
     public var originalCache: ImageCache? = nil
     public var originalCache: ImageCache? = nil

+ 2 - 2
Sources/Image/ImageProcessor.swift

@@ -34,7 +34,7 @@ import UIKit
 #endif
 #endif
 
 
 /// Represents an item which could be processed by an `ImageProcessor`.
 /// Represents an item which could be processed by an `ImageProcessor`.
-public enum ImageProcessItem {
+public enum ImageProcessItem: Sendable {
     
     
     /// Input image. The processor should provide a method to apply
     /// Input image. The processor should provide a method to apply
     /// processing to this `image` and return the resulting image.
     /// processing to this `image` and return the resulting image.
@@ -46,7 +46,7 @@ public enum ImageProcessItem {
 }
 }
 
 
 /// An `ImageProcessor` is used to convert downloaded data into an image.
 /// An `ImageProcessor` is used to convert downloaded data into an image.
-public protocol ImageProcessor {
+public protocol ImageProcessor: Sendable {
     
     
     /// Identifier for the processor.
     /// Identifier for the processor.
     ///
     ///

+ 1 - 1
Sources/Networking/SessionDataTask.swift

@@ -30,7 +30,7 @@ import Foundation
 ///
 ///
 /// Essentially, a ``SessionDataTask`` wraps a `URLSessionDataTask` and manages the download data.
 /// Essentially, a ``SessionDataTask`` wraps a `URLSessionDataTask` and manages the download data.
 /// It uses a ``SessionDataTask/CancelToken`` to track the task and manage its cancellation.
 /// It uses a ``SessionDataTask/CancelToken`` to track the task and manage its cancellation.
-public class SessionDataTask {
+public class SessionDataTask: @unchecked Sendable {
 
 
     /// Represents the type of token used for canceling a task.
     /// Represents the type of token used for canceling a task.
     public typealias CancelToken = Int
     public typealias CancelToken = Int