diff --git a/ReerKit.xcodeproj/project.pbxproj b/ReerKit.xcodeproj/project.pbxproj index 2b30abe..cef62d9 100644 --- a/ReerKit.xcodeproj/project.pbxproj +++ b/ReerKit.xcodeproj/project.pbxproj @@ -677,6 +677,11 @@ D094C96229F4606600491CD8 /* UIDeviceExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D094C96129F4606600491CD8 /* UIDeviceExtensionsTests.swift */; }; D094C96429F4631200491CD8 /* Memory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D094C96329F4631200491CD8 /* Memory.swift */; }; D094C96629F46A0C00491CD8 /* MemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D094C96529F46A0C00491CD8 /* MemoryTests.swift */; }; + D0991CB22CBA56C100C6BE5A /* MutexLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0991CB12CBA56C100C6BE5A /* MutexLock.swift */; }; + D0991CB32CBA56C100C6BE5A /* MutexLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0991CB12CBA56C100C6BE5A /* MutexLock.swift */; }; + D0991CB42CBA56C100C6BE5A /* MutexLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0991CB12CBA56C100C6BE5A /* MutexLock.swift */; }; + D0991CB52CBA56C100C6BE5A /* MutexLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0991CB12CBA56C100C6BE5A /* MutexLock.swift */; }; + D0991CB62CBA56C100C6BE5A /* MutexLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0991CB12CBA56C100C6BE5A /* MutexLock.swift */; }; D09D724029DC94BF00636935 /* big_buck_bunny_720p_1mb.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = D09D723F29DC94BF00636935 /* big_buck_bunny_720p_1mb.mp4 */; }; D0A0040628620D9900D2FA7C /* TypeNameDescribableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A0040528620D9900D2FA7C /* TypeNameDescribableTests.swift */; }; D0A6B3A32924AD11008B7FDA /* UIResponder+REExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A6B3A22924AD11008B7FDA /* UIResponder+REExtensions.swift */; }; @@ -992,6 +997,7 @@ D094C96129F4606600491CD8 /* UIDeviceExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDeviceExtensionsTests.swift; sourceTree = ""; }; D094C96329F4631200491CD8 /* Memory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Memory.swift; sourceTree = ""; }; D094C96529F46A0C00491CD8 /* MemoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryTests.swift; sourceTree = ""; }; + D0991CB12CBA56C100C6BE5A /* MutexLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutexLock.swift; sourceTree = ""; }; D09D723F29DC94BF00636935 /* big_buck_bunny_720p_1mb.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = big_buck_bunny_720p_1mb.mp4; sourceTree = ""; }; D0A0040528620D9900D2FA7C /* TypeNameDescribableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeNameDescribableTests.swift; sourceTree = ""; }; D0A6B3A22924AD11008B7FDA /* UIResponder+REExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIResponder+REExtensions.swift"; sourceTree = ""; }; @@ -1312,6 +1318,7 @@ D0038B7E2856581600A890F9 /* UnfairLock.swift */, D0038B8028565B9400A890F9 /* ReadWriteLock.swift */, D004CC48285A41F500C41360 /* Synchronizing.swift */, + D0991CB12CBA56C100C6BE5A /* MutexLock.swift */, ); path = Lock; sourceTree = ""; @@ -2160,6 +2167,7 @@ D01D6DCE2A06CBE000AEDA3D /* Vibrator.swift in Sources */, D0D311392AB8522F00E54361 /* Rounded.swift in Sources */, D04B85DC29F9A50600177357 /* Throttler.swift in Sources */, + D0991CB32CBA56C100C6BE5A /* MutexLock.swift in Sources */, D04B861029F9A59600177357 /* UIViewController+REExtensions.swift in Sources */, D04B85DD29F9A50600177357 /* Debouncer.swift in Sources */, D04B861929F9A59600177357 /* UITableView+REExtensions.swift in Sources */, @@ -2307,6 +2315,7 @@ D01D6DCF2A06CBE000AEDA3D /* Vibrator.swift in Sources */, D0D3113A2AB8522F00E54361 /* Rounded.swift in Sources */, D04B86F929F9A71100177357 /* URLRequest+REExtensions.swift in Sources */, + D0991CB42CBA56C100C6BE5A /* MutexLock.swift in Sources */, D04B868029F9A6D900177357 /* Color+REExtensions.swift in Sources */, D04B86BC29F9A6FC00177357 /* WeakProxy.swift in Sources */, D04B872929F9A71900177357 /* UIResponder+REExtensions.swift in Sources */, @@ -2453,6 +2462,7 @@ D01D6DD02A06CBE000AEDA3D /* Vibrator.swift in Sources */, D0D3113B2AB8522F00E54361 /* Rounded.swift in Sources */, D04B86EB29F9A71000177357 /* URLRequest+REExtensions.swift in Sources */, + D0991CB52CBA56C100C6BE5A /* MutexLock.swift in Sources */, D04B867D29F9A6D800177357 /* Color+REExtensions.swift in Sources */, D04B86C029F9A6FD00177357 /* WeakProxy.swift in Sources */, D04B870829F9A71900177357 /* UIResponder+REExtensions.swift in Sources */, @@ -2504,6 +2514,7 @@ D0185A7A2C7F501900100E3E /* NanoID.swift in Sources */, D0185A7B2C7F501900100E3E /* Reachability.swift in Sources */, D0185A7C2C7F501900100E3E /* GlobalFunctions.swift in Sources */, + D0991CB62CBA56C100C6BE5A /* MutexLock.swift in Sources */, D0185A7D2C7F501900100E3E /* RETimer.swift in Sources */, D0185A7E2C7F501900100E3E /* Invocation.swift in Sources */, D0185A7F2C7F501900100E3E /* CountdownTimer.swift in Sources */, @@ -2766,6 +2777,7 @@ D0D311242AB4458F00E54361 /* CALayer+REExtensions.swift in Sources */, D0B1211E2855156200B5B326 /* TypeNameDescribable.swift in Sources */, D07E53AF2883137000921873 /* WeakProxy.swift in Sources */, + D0991CB22CBA56C100C6BE5A /* MutexLock.swift in Sources */, D0122B0B29EEFEB8008311CF /* UICollectionView+REExtensions.swift in Sources */, D004CC49285A41F500C41360 /* Synchronizing.swift in Sources */, D01DABC229B4FAA700ABD25E /* Throttler.swift in Sources */, diff --git a/Sources/Foundation/Data+REExtensions.swift b/Sources/Foundation/Data+REExtensions.swift index 0ebc8c0..8433f88 100644 --- a/Sources/Foundation/Data+REExtensions.swift +++ b/Sources/Foundation/Data+REExtensions.swift @@ -151,7 +151,7 @@ public extension ReerForEquatable where Base == Data { throw JSONError.invalidArray } } - + #if !os(Linux) /// ReerKit: Generate a random length of Data. static func random(ofLength length: Int) -> Data { var randomData = Data(count: length) @@ -164,6 +164,7 @@ public extension ReerForEquatable where Base == Data { return Data((0.. Int { return numberOfLines(forWidth: width, ignoreBlankLines: ignoreBlankLines) } - #if !os(Linux) /// ReerKit: Calculate lines for a `NSAttributedString` with a width constrained. /// - Parameters: /// - width: A constrained of container view width. @@ -77,7 +77,6 @@ public extension Reer where Base: NSAttributedString { return numberOfLines } - #endif /// ReerKit: Calculate height for a `NSAttributedString` with a constrained width. /// - Parameter width: A constrained of container view width. @@ -87,13 +86,14 @@ public extension Reer where Base: NSAttributedString { let rect = base.boundingRect(with: maxSize, options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil) return rect.height } + #endif /// ReerKit: Applies given attributes to the new instance of NSAttributedString initialized with self object. /// /// - Parameter attributes: Dictionary of attributes. /// - Returns: NSAttributedString with applied attributes. func with(attributes: [NSAttributedString.Key: Any]) -> NSMutableAttributedString { - guard !base.string.isEmpty else { return NSMutableAttributedString() } + guard !base.string.isEmpty else { return NSMutableAttributedString(string: "") } let copy = NSMutableAttributedString(attributedString: base) copy.addAttributes(attributes, range: NSRange(0.. NSMutableAttributedString { - guard let pattern = try? NSRegularExpression(pattern: pattern, options: options) else { return NSMutableAttributedString() } + guard let pattern = try? NSRegularExpression(pattern: pattern, options: options) else { return NSMutableAttributedString(string: "") } let matches = pattern.matches(in: base.string, options: [], range: NSRange(0.., - using block: @escaping ( - _ result: NSTextCheckingResult?, - _ flags: MatchingFlags, - _ stop: inout Bool - ) -> Void - ) { - base.enumerateMatches( - in: string, - options: options, - range: NSRange(range, in: string) - ) { result, flags, stop in - var shouldStop = false - block(result, flags, &shouldStop) - if shouldStop { - stop.pointee = true - } - } - } -#else func enumerateMatches( in string: String, options: NSRegularExpression.MatchingOptions = [], @@ -80,7 +56,6 @@ public extension Reer where Base: NSRegularExpression { } } } -#endif /// ReerKit: Returns an array containing all the matches of the regular expression in the string. /// diff --git a/Sources/StandardLibrary/AnyObjectExtensions/AnyObjectExtensionable.swift b/Sources/StandardLibrary/AnyObjectExtensions/AnyObjectExtensionable.swift index c5b190a..43e5d57 100644 --- a/Sources/StandardLibrary/AnyObjectExtensions/AnyObjectExtensionable.swift +++ b/Sources/StandardLibrary/AnyObjectExtensions/AnyObjectExtensionable.swift @@ -21,8 +21,11 @@ /// ReerKit: Combinations of AnyObject extension protocols. /// You must conform this protocol by yourself if your class is NOT inheriting from `NSObject`. + +#if canImport(ObjectiveC) public typealias AnyObjectExtensionable = Associatable & OnceExecutable & Swizzlable & DeinitObservable +#endif diff --git a/Sources/Utility/Debouncer.swift b/Sources/Utility/Debouncer.swift index 05a7eb9..e4bf1d0 100644 --- a/Sources/Utility/Debouncer.swift +++ b/Sources/Utility/Debouncer.swift @@ -25,7 +25,11 @@ import Foundation public final class Debouncer { private let queue: DispatchQueue public private(set) var workItem = DispatchWorkItem(block: {}) + #if os(Linux) + private let lock = MutexLock() + #else private let lock = UnfairLock() + #endif public init(queue: DispatchQueue = .main) { self.queue = queue diff --git a/Sources/Utility/GlobalFunctions.swift b/Sources/Utility/GlobalFunctions.swift index 9d9cdaa..8b7ebf1 100644 --- a/Sources/Utility/GlobalFunctions.swift +++ b/Sources/Utility/GlobalFunctions.swift @@ -19,7 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#if canImport(Dispatch) +#if canImport(Dispatch) && !os(Linux) import Dispatch /// ReerKit: Get current queue label. diff --git a/Sources/Utility/Lock/UnfairLock.swift b/Sources/Utility/Lock/UnfairLock.swift index 8d96c11..b840edd 100644 --- a/Sources/Utility/Lock/UnfairLock.swift +++ b/Sources/Utility/Lock/UnfairLock.swift @@ -19,7 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#if canImport(os) +#if canImport(os) && !os(Linux) import os.lock /// ReerKit: A wrapper of `os_unfair_lock` diff --git a/Sources/Utility/Throttler.swift b/Sources/Utility/Throttler.swift index 8981271..0a4bc3f 100644 --- a/Sources/Utility/Throttler.swift +++ b/Sources/Utility/Throttler.swift @@ -32,7 +32,11 @@ public final class Throttler { private var isPending = false private var hasExecuted = false private var latestAction: () -> Void = {} + #if os(Linux) + private let lock = MutexLock() + #else private let lock = UnfairLock() + #endif private let queue: DispatchQueue private let performMode: PerformMode diff --git a/Sources/Utility/Weak/WeakProxy.swift b/Sources/Utility/Weak/WeakProxy.swift index f73365b..f323e38 100644 --- a/Sources/Utility/Weak/WeakProxy.swift +++ b/Sources/Utility/Weak/WeakProxy.swift @@ -19,7 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#if canImport(Foundation) +#if canImport(Foundation) && !os(Linux) import Foundation /// A proxy used to hold a weak object.