Skip to content

Commit

Permalink
Merge pull request #2239 from onevcat/concurrency/data-types
Browse files Browse the repository at this point in the history
Strict concurrency is ready
  • Loading branch information
onevcat authored Apr 20, 2024
2 parents 420f6de + d2aa3b6 commit ef7bae9
Show file tree
Hide file tree
Showing 47 changed files with 911 additions and 434 deletions.
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

0 comments on commit ef7bae9

Please sign in to comment.