onevcat пре 1 година
родитељ
комит
6213b7c9ae

+ 2 - 2
Sources/Image/Placeholder.swift

@@ -44,7 +44,7 @@ public protocol Placeholder {
     /// given `imageView`.
     ///
     /// - Parameter imageView: The image view where the placeholder should be added to.
-    func add(to imageView: KFCrossPlatformImageView)
+    @MainActor func add(to imageView: KFCrossPlatformImageView)
     
     /// Called when the placeholder needs to be removed from a given image view.
     ///
@@ -52,7 +52,7 @@ public protocol Placeholder {
     /// given `imageView`.
     ///
     /// - Parameter imageView: The image view where the placeholder is already added to and now should be removed from.
-    func remove(from imageView: KFCrossPlatformImageView)
+    @MainActor func remove(from imageView: KFCrossPlatformImageView)
 }
 
 extension KFCrossPlatformImage: Placeholder {

+ 33 - 34
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -27,7 +27,6 @@
 import XCTest
 @testable import Kingfisher
 
-@MainActor
 class ImageViewExtensionTests: XCTestCase {
 
     var imageView: KFCrossPlatformImageView!
@@ -60,7 +59,7 @@ class ImageViewExtensionTests: XCTestCase {
         super.tearDown()
     }
 
-    func testImageDownloadForImageView() {
+    @MainActor func testImageDownloadForImageView() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData, length: 123)
@@ -90,7 +89,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testImageDownloadCompletionHandlerRunningOnMainQueue() {
+    @MainActor func testImageDownloadCompletionHandlerRunningOnMainQueue() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -108,7 +107,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testImageDownloadWithResourceForImageView() {
+    @MainActor func testImageDownloadWithResourceForImageView() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData, length: 123)
@@ -137,7 +136,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testImageDownloadCancelForImageView() {
+    @MainActor func testImageDownloadCancelForImageView() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData, length: 123)
@@ -157,7 +156,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
 
-    func testImageDownloadCancelPartialTaskBeforeRequest() {
+    @MainActor func testImageDownloadCancelPartialTaskBeforeRequest() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData)
@@ -189,7 +188,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testImageDownloadCancelAllTasksAfterRequestStarted() {
+    @MainActor func testImageDownloadCancelAllTasksAfterRequestStarted() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData)
@@ -225,7 +224,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testImageDownloadMultipleCaches() {
+    @MainActor func testImageDownloadMultipleCaches() {
         
         let cache1 = ImageCache(name: "cache1")
         let cache2 = ImageCache(name: "cache2")
@@ -259,7 +258,7 @@ class ImageViewExtensionTests: XCTestCase {
         }
     }
     
-    func testIndicatorViewExisting() {
+    @MainActor func testIndicatorViewExisting() {
         imageView.kf.indicatorType = .activity
         XCTAssertNotNil(imageView.kf.indicator)
         XCTAssertTrue(imageView.kf.indicator is ActivityIndicator)
@@ -268,7 +267,7 @@ class ImageViewExtensionTests: XCTestCase {
         XCTAssertNil(imageView.kf.indicator)
     }
     
-    func testCustomizeStructIndicatorExisting() {
+    @MainActor func testCustomizeStructIndicatorExisting() {
         struct StructIndicator: Indicator {
             let view = KFCrossPlatformView()
             func startAnimatingView() {}
@@ -283,7 +282,7 @@ class ImageViewExtensionTests: XCTestCase {
         XCTAssertNil(imageView.kf.indicator)
     }
     
-    func testActivityIndicatorViewAnimating() {
+    @MainActor func testActivityIndicatorViewAnimating() {
         imageView.kf.indicatorType = .activity
         
         let exp = expectation(description: #function)
@@ -305,7 +304,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testCanUseImageIndicatorViewAnimating() {
+    @MainActor func testCanUseImageIndicatorViewAnimating() {
         
         imageView.kf.indicatorType = .image(imageData: testImageData)
         XCTAssertTrue(imageView.kf.indicator is ImageIndicator)
@@ -331,7 +330,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testCancelImageTask() {
+    @MainActor func testCancelImageTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData)
@@ -348,7 +347,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testDownloadForMultipleURLs() {
+    @MainActor func testDownloadForMultipleURLs() {
         let exp = expectation(description: #function)
 
         stub(testURLs[0], data: testImageData)
@@ -383,7 +382,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingNilURL() {
+    @MainActor func testSettingNilURL() {
         let exp = expectation(description: #function)
         let url: URL? = nil
         imageView.kf.setImage(with: url, progressBlock: { _, _ in XCTFail() }) {
@@ -399,7 +398,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingImageWhileKeepingCurrentOne() {
+    @MainActor func testSettingImageWhileKeepingCurrentOne() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -419,7 +418,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingImageKeepingRespectingPlaceholder() {
+    @MainActor func testSettingImageKeepingRespectingPlaceholder() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -442,7 +441,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSetGIFImageOnlyFirstFrameThenFullFrames() {
+    @MainActor func testSetGIFImageOnlyFirstFrameThenFullFrames() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageGIFData, length: 123)
@@ -494,7 +493,7 @@ class ImageViewExtensionTests: XCTestCase {
     }
     
     // https://github.com/onevcat/Kingfisher/issues/1923
-    func testLoadGIFImageWithDifferentOptions() {
+    @MainActor func testLoadGIFImageWithDifferentOptions() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageGIFData)
@@ -516,7 +515,7 @@ class ImageViewExtensionTests: XCTestCase {
     
     // https://github.com/onevcat/Kingfisher/issues/665
     // The completion handler should be called even when the image view loading url gets changed.
-    func testIssue665() {
+    @MainActor func testIssue665() {
         let exp = expectation(description: #function)
 
         stub(testURLs[0], data: testImageData)
@@ -538,7 +537,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
 
-    func testImageSettingWithPlaceholder() {
+    @MainActor func testImageSettingWithPlaceholder() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
 
@@ -564,7 +563,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
 
-    func testImageSettingWithCustomizePlaceholder() {
+    @MainActor func testImageSettingWithCustomizePlaceholder() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
 
@@ -592,7 +591,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
 
-    func testSettingNonWorkingImageWithCustomizePlaceholderAndFailureImage() {
+    @MainActor func testSettingNonWorkingImageWithCustomizePlaceholderAndFailureImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
 
@@ -614,7 +613,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingNonWorkingImageWithFailureImage() {
+    @MainActor func testSettingNonWorkingImageWithFailureImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, errorCode: 404)
@@ -637,7 +636,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
     
-    func testSettingNonWorkingImageWithEmptyFailureImage() {
+    @MainActor func testSettingNonWorkingImageWithEmptyFailureImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, errorCode: 404)
@@ -652,7 +651,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
     
-    func testSettingNonWorkingImageWithoutFailureImage() {
+    @MainActor func testSettingNonWorkingImageWithoutFailureImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, errorCode: 404)
@@ -668,7 +667,7 @@ class ImageViewExtensionTests: XCTestCase {
     }
     
     // https://github.com/onevcat/Kingfisher/issues/1053
-    func testSetSameURLWithDifferentProcessors() {
+    @MainActor func testSetSameURLWithDifferentProcessors() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         
@@ -700,7 +699,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testMemoryImageCacheExtendingExpirationTask() {
+    @MainActor func testMemoryImageCacheExtendingExpirationTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -735,7 +734,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testMemoryImageCacheNotExtendingExpirationTask() {
+    @MainActor func testMemoryImageCacheNotExtendingExpirationTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -768,7 +767,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
 
-    func testDiskImageCacheExtendingExpirationTask() {
+    @MainActor func testDiskImageCacheExtendingExpirationTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -800,7 +799,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
 
-    func testDiskImageCacheNotExtendingExpirationTask() {
+    @MainActor func testDiskImageCacheNotExtendingExpirationTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -833,7 +832,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
 
-    func testImageSettingWithAlternativeSource() {
+    @MainActor func testImageSettingWithAlternativeSource() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData)
@@ -853,7 +852,7 @@ class ImageViewExtensionTests: XCTestCase {
         waitForExpectations(timeout: 1, handler: nil)
     }
 
-    func testImageSettingCanCancelAlternativeSource() {
+    @MainActor func testImageSettingCanCancelAlternativeSource() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let dataStub = delayedStub(url, data: testImageData)
@@ -892,7 +891,7 @@ class ImageViewExtensionTests: XCTestCase {
     }
 
     @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
-    func testLowDataModeSource() {
+    @MainActor func testLowDataModeSource() {
         let exp = expectation(description: #function)
 
         let url = testURLs[0]

+ 3 - 3
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -1298,7 +1298,7 @@ extension KFCrossPlatformImage {
     }
 }
 
-class SimpleProcessor: ImageProcessor {
+final class SimpleProcessor: ImageProcessor, @unchecked Sendable {
     public let identifier = "id"
     var processed = false
     /// Initialize a `DefaultImageProcessor`
@@ -1326,7 +1326,7 @@ class SimpleProcessor: ImageProcessor {
     }
 }
 
-class FailingProcessor: ImageProcessor {
+final class FailingProcessor: ImageProcessor, @unchecked Sendable {
     public let identifier = "FailingProcessor"
     var processed = false
     public init() {}
@@ -1336,7 +1336,7 @@ class FailingProcessor: ImageProcessor {
     }
 }
 
-struct SimpleImageDataProvider: ImageDataProvider {
+struct SimpleImageDataProvider: ImageDataProvider, @unchecked Sendable {
     let cacheKey: String
     let provider: () -> (Result<Data, Error>)
     

+ 7 - 8
Tests/KingfisherTests/UIButtonExtensionTests.swift

@@ -29,7 +29,6 @@ import UIKit
 import XCTest
 @testable import Kingfisher
 
-@MainActor
 class UIButtonExtensionTests: XCTestCase {
 
     var button: UIButton!
@@ -61,7 +60,7 @@ class UIButtonExtensionTests: XCTestCase {
         super.tearDown()
     }
 
-    func testDownloadAndSetImage() {
+    @MainActor func testDownloadAndSetImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData, length: 123)
@@ -87,7 +86,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testDownloadAndSetBackgroundImage() {
+    @MainActor func testDownloadAndSetBackgroundImage() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         stub(url, data: testImageData, length: 123)
@@ -111,7 +110,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testCancelImageTask() {
+    @MainActor func testCancelImageTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData)
@@ -129,7 +128,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testCancelBackgroundImageTask() {
+    @MainActor func testCancelBackgroundImageTask() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
         let stub = delayedStub(url, data: testImageData)
@@ -147,7 +146,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingNilURL() {
+    @MainActor func testSettingNilURL() {
         let exp = expectation(description: #function)
         
         let url: URL? = nil
@@ -164,7 +163,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 3, handler: nil)
     }
     
-    func testSettingNonWorkingImageWithFailureImage() {
+    @MainActor func testSettingNonWorkingImageWithFailureImage() {
         let expectation = self.expectation(description: "wait for downloading image")
         let url = testURLs[0]
         stub(url, errorCode: 404)
@@ -181,7 +180,7 @@ class UIButtonExtensionTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
     
-    func testSettingNonWorkingBackgroundImageWithFailureImage() {
+    @MainActor func testSettingNonWorkingBackgroundImageWithFailureImage() {
         let expectation = self.expectation(description: "wait for downloading image")
         let url = testURLs[0]
         stub(url, errorCode: 404)