diff --git a/Sources/Xcore/Cocoa/Extensions/AVFoundation+Extensions.swift b/Sources/Xcore/Cocoa/Extensions/AVFoundation+Extensions.swift index 0a2eef03e..8673ba39d 100644 --- a/Sources/Xcore/Cocoa/Extensions/AVFoundation+Extensions.swift +++ b/Sources/Xcore/Cocoa/Extensions/AVFoundation+Extensions.swift @@ -49,7 +49,7 @@ extension AVPlayerItem { /// `nil`, this method looks in the main bundle of the current application. /// - Returns: An instance of AVPlayerItem. public convenience init?(filename: String, bundle: Bundle? = nil) { - guard let url = (bundle ?? Bundle.main).url(filename: filename) else { + guard let url = (bundle ?? .main).url(filename: filename) else { return nil } @@ -78,7 +78,7 @@ extension AVAsset { /// `nil`, this method looks in the main bundle of the current application. /// - Returns: An instance of AVAsset. public convenience init?(filename: String, bundle: Bundle? = nil) { - guard let url = (bundle ?? Bundle.main).url(filename: filename) else { + guard let url = (bundle ?? .main).url(filename: filename) else { return nil } diff --git a/Sources/Xcore/Cocoa/Extensions/NSError+Extensions.swift b/Sources/Xcore/Cocoa/Extensions/NSError+Extensions.swift index cfca79433..b42c06362 100644 --- a/Sources/Xcore/Cocoa/Extensions/NSError+Extensions.swift +++ b/Sources/Xcore/Cocoa/Extensions/NSError+Extensions.swift @@ -6,6 +6,13 @@ import Foundation +extension NSError { + /// Returns an error with random domain and code. + public static func random() -> Self { + .init(domain: .random(), code: .random(), userInfo: nil) + } +} + extension NSError { /// Appends the given dictionary to the existing `userInfo` dictionary replacing /// any existing values with newer ones. @@ -20,10 +27,3 @@ extension NSError { ) } } - -extension NSError { - /// Returns an error with random domain and code. - public static func random() -> Self { - .init(domain: .random(), code: .random(), userInfo: nil) - } -} diff --git a/Sources/Xcore/Cocoa/Extensions/NotificationCenter+Extensions.swift b/Sources/Xcore/Cocoa/Extensions/NotificationCenter+Extensions.swift index 0fe30b416..a24a19e45 100644 --- a/Sources/Xcore/Cocoa/Extensions/NotificationCenter+Extensions.swift +++ b/Sources/Xcore/Cocoa/Extensions/NotificationCenter+Extensions.swift @@ -38,7 +38,7 @@ extension NotificationCenter { /// delivery. /// - Returns: An asynchronous sequence of notifications from the center. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) - public static func async(_ name: Notification.Name, object: AnyObject? = nil) -> NotificationCenter.Notifications { + public static func async(_ name: Notification.Name, object: AnyObject? = nil) -> Notifications { shared.notifications(named: name, object: object) } } @@ -98,12 +98,10 @@ extension NotificationCenter { userInfo: [AnyHashable: Any]? = nil, delayInterval: TimeInterval = 0 ) { - guard delayInterval > 0 else { - shared.post(name: name, object: object, userInfo: userInfo) - return - } - - Timer.after(delayInterval) { + Task { + if delayInterval > 0 { + try await Task.sleep(for: .seconds(delayInterval)) + } shared.post(name: name, object: object, userInfo: userInfo) } } @@ -137,6 +135,6 @@ extension NotificationCenter { } private static var shared: NotificationCenter { - NotificationCenter.default + .default } } diff --git a/Sources/Xcore/Cocoa/Extensions/UIImage+Extensions.swift b/Sources/Xcore/Cocoa/Extensions/UIImage+Extensions.swift index cde946b27..eadd5dd73 100644 --- a/Sources/Xcore/Cocoa/Extensions/UIImage+Extensions.swift +++ b/Sources/Xcore/Cocoa/Extensions/UIImage+Extensions.swift @@ -15,6 +15,8 @@ extension UIImage { case png /// Encoding format in JPEG format. case jpeg(quality: Double) + /// Encoding format in HEIC format. + case heic } /// Returns a data object that contains the specified image in a given format. @@ -26,6 +28,11 @@ extension UIImage { return pngData() case let .jpeg(quality): return jpegData(compressionQuality: quality) + case .heic: + if #available(iOS 17.0, *) { + return heicData() + } + return nil } } } diff --git a/Sources/Xcore/Cocoa/Extensions/WKWebsiteDataStore+Extensions.swift b/Sources/Xcore/Cocoa/Extensions/WKWebsiteDataStore+Extensions.swift index 06b73da18..ce242db56 100644 --- a/Sources/Xcore/Cocoa/Extensions/WKWebsiteDataStore+Extensions.swift +++ b/Sources/Xcore/Cocoa/Extensions/WKWebsiteDataStore+Extensions.swift @@ -25,10 +25,10 @@ extension WKWebsiteDataStore { } public func remove(_ type: DataType, _ completion: (() -> Void)? = nil) { - fetchDataRecords(ofTypes: type.dataTypes) { [weak self] records in - self?.removeData(ofTypes: type.dataTypes, for: records) { - completion?() - } + Task { + let records = await dataRecords(ofTypes: type.dataTypes) + await removeData(ofTypes: type.dataTypes, for: records) + completion?() } } }