Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict concurrency is ready #2239

Merged
merged 29 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
86e7bfa
Make ImageTransition Sendable
onevcat Apr 13, 2024
1680c9e
Mark protocols sendable
onevcat Apr 13, 2024
b2a4506
Improve some test Sendable
onevcat Apr 13, 2024
22863e0
Disk storage fully sendable
onevcat Apr 13, 2024
8d8caf2
Mark final to support Sendable
onevcat Apr 13, 2024
3bca097
Mark sendable for closures
onevcat Apr 14, 2024
e2ca7fb
Mark necessary types as Sendable
onevcat Apr 14, 2024
cd9f37f
Cache can be sendable
onevcat Apr 14, 2024
2721186
Mark manager class sendable
onevcat Apr 15, 2024
bc11fd0
Fix warning for image class
onevcat Apr 15, 2024
a00caea
Mark ImageProgressive sendable
onevcat Apr 15, 2024
7fc722b
Change image modifier as Sendable
onevcat Apr 15, 2024
eb56be5
Fix all warnings for target concurrency
onevcat Apr 15, 2024
6e0f6bb
Verify and mark more sendable
onevcat Apr 15, 2024
80f947d
Fix downloader concurrency issue
onevcat Apr 16, 2024
3ad65f8
Fix more Sendable warnings
onevcat Apr 16, 2024
f3e8d9c
Sendable warnings for RetrievingContext
onevcat Apr 16, 2024
1605d11
Fix retryContext and its tests for concurrency
onevcat Apr 16, 2024
50b54c7
Fix tests and temporarily mark main actor
onevcat Apr 16, 2024
441db82
Solve more warnings on Sendable
onevcat Apr 17, 2024
5d2174d
Resolve more Sendable warnings and fix tests
onevcat Apr 17, 2024
76425c5
Explicitly mark main queue helper block
onevcat Apr 19, 2024
3d7d2ce
KingfisherParsedOptionsInfo can be safe Sendable
onevcat Apr 19, 2024
631c3c2
Make KFImage.Context as Sendable
onevcat Apr 19, 2024
10e5dbf
Fix test with isolated values
onevcat Apr 19, 2024
d4e29b4
Solve warnings for macOS target
onevcat Apr 20, 2024
46389e5
Fix concurrency warnings for tvOS
onevcat Apr 20, 2024
17d840d
Fix warnings for watchOS
onevcat Apr 20, 2024
d2aa3b6
Mark SWIFT_STRICT_CONCURRENCY to complete
onevcat Apr 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ProgressiveJPEGViewController: UIViewController {
processorIdentifier: self.processor.identifier,
callbackQueue: .mainAsync,
completionHandler: {
self.loadImage()
Task { @MainActor in self.loadImage() }
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class TextAttachmentViewController: UIViewController {
attributedText.replaceCharacters(in: NSRange(), with: NSAttributedString(attachment: textAttachment))
label.attributedText = attributedText

let label = getLabel()
KF.url(URL(string: "https://onevcat.com/assets/images/avatar.jpg")!)
.resizing(referenceSize: CGSize(width: 30, height: 30))
.roundCorner(radius: .point(15))
.set(to: textAttachment, attributedView: self.getLabel())
.set(to: textAttachment, attributedView: label)
}

func getLabel() -> UILabel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class InterfaceController: WKInterfaceController {
func refreshImage() {
let url = URL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/kingfisher-\(currentIndex! + 1).jpg")!
print("Start loading... \(url)")
interfaceImage.kf.setImage(with: url) { r in
interfaceImage.kf.setImage(with: url, completionHandler: { r in
print(r)
}
})
}

override func willActivate() {
Expand Down
2 changes: 2 additions & 0 deletions Kingfisher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_INSTALL_OBJC_HEADER = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down Expand Up @@ -1185,6 +1186,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_INSTALL_OBJC_HEADER = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_STRICT_CONCURRENCY = complete;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
18 changes: 12 additions & 6 deletions Sources/Cache/DiskStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ public enum DiskStorage {
/// ``DiskStorage/Config`` value or by modifying the ``DiskStorage/Backend/config`` property after it has been
/// created. The ``DiskStorage/Backend`` will use the file's attributes to keep track of a file for its expiration
/// or size limitation.
public class Backend<T: DataTransformable> {
public class Backend<T: DataTransformable>: @unchecked Sendable {

private let propertyQueue = DispatchQueue(label: "com.onevcat.kingfisher.DiskStorage.Backend.propertyQueue")

private var _config: Config
/// The configuration used for this disk storage.
///
/// It is a value you can set and use to configure the storage as needed.
public var config: Config
public var config: Config {
get { propertyQueue.sync { _config } }
set { propertyQueue.sync { _config = newValue } }
}

/// The final storage URL on disk of the disk storage ``DiskStorage/Backend``, considering the
/// ``DiskStorage/Config/name`` and the ``DiskStorage/Config/cachePathBlock``.
Expand Down Expand Up @@ -83,7 +89,7 @@ public enum DiskStorage {

// Break any possible retain cycle set by outside.
config.cachePathBlock = nil
self.config = config
_config = config

metaChangingQueue = DispatchQueue(label: creation.cacheName)
setupCacheChecking()
Expand Down Expand Up @@ -255,7 +261,7 @@ public enum DiskStorage {
let data = try Data(contentsOf: fileURL)
let obj = try T.fromData(data)
metaChangingQueue.async {
meta.extendExpiration(with: fileManager, extendingExpiration: extendingExpiration)
meta.extendExpiration(with: self.config.fileManager, extendingExpiration: extendingExpiration)
}
return obj
} catch {
Expand Down Expand Up @@ -463,7 +469,7 @@ public enum DiskStorage {
extension DiskStorage {

/// Represents the configuration used in a ``DiskStorage/Backend``.
public struct Config {
public struct Config: @unchecked Sendable {

/// The file size limit on disk of the storage in bytes.
///
Expand Down Expand Up @@ -496,7 +502,7 @@ extension DiskStorage {
/// A closure that takes in the initial directory path and generates the final disk cache path.
///
/// You can use it to fully customize your cache path.
public var cachePathBlock: ((_ directory: URL, _ cacheName: String) -> URL)! = {
public var cachePathBlock: (@Sendable (_ directory: URL, _ cacheName: String) -> URL)! = {
(directory, cacheName) in
return directory.appendingPathComponent(cacheName, isDirectory: true)
}
Expand Down
Loading
Loading