From 12c6f4fa79b0fbffa3e53603418b4315a3854c5b Mon Sep 17 00:00:00 2001 From: Zeeshan Mian Date: Mon, 12 Feb 2024 21:18:00 +1100 Subject: [PATCH] Added Sendable --- Sources/Xcore/Swift/Components/ElementPosition.swift | 8 ++++---- .../SystemAlert/SystemAlertConfiguration.swift | 2 +- .../Xcore/Swift/Components/Money/Money+Color.swift | 2 +- Sources/Xcore/Swift/Components/Money/Money+Font.swift | 4 ++-- .../Xcore/Swift/Components/Money/Money+Style.swift | 11 ++++++----- Sources/Xcore/Swift/Components/Money/Money.swift | 4 ++-- Sources/Xcore/Swift/Components/SelectionType.swift | 4 ++++ .../Components/Transformer/AsyncTransformer.swift | 6 +++--- .../Swift/Components/Transformer/Transformer.swift | 6 +++--- .../Validation/ValidationRule+Operators.swift | 4 ++-- .../Swift/Components/Validation/ValidationRule.swift | 6 +++--- .../Numbers/CustomFloatingPointFormatStyle.swift | 6 +++--- .../Swift/Extensions/Numbers/SignedNumericSign.swift | 2 +- .../Xcore/Swift/Extensions/URL/URL+Extensions.swift | 2 +- Sources/Xcore/Swift/PropertyWrappers/Percentage.swift | 2 +- .../Swift/Protocols/DoubleOrDecimalProtocol.swift | 2 +- 16 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Sources/Xcore/Swift/Components/ElementPosition.swift b/Sources/Xcore/Swift/Components/ElementPosition.swift index b5263993d..3aa065bd2 100644 --- a/Sources/Xcore/Swift/Components/ElementPosition.swift +++ b/Sources/Xcore/Swift/Components/ElementPosition.swift @@ -6,7 +6,7 @@ import Foundation -public struct ElementPosition: OptionSet { +public struct ElementPosition: OptionSet, Sendable { public let rawValue: Int public init(rawValue: Int) { @@ -21,7 +21,7 @@ public struct ElementPosition: OptionSet { // MARK: - ButtonIdentifier -public enum ButtonIdentifierTag {} +public enum ButtonIdentifierTag: Sendable {} public typealias ButtonIdentifier = Identifier extension ButtonIdentifier { @@ -32,7 +32,7 @@ extension ButtonIdentifier { // MARK: - ButtonState -public enum ButtonState { +public enum ButtonState: Sendable { case normal case pressed case disabled @@ -40,7 +40,7 @@ public enum ButtonState { // MARK: - ButtonProminence -public enum ButtonProminence { +public enum ButtonProminence: Sendable { case fill case outline } diff --git a/Sources/Xcore/Swift/Components/FeatureFlag/SystemAlert/SystemAlertConfiguration.swift b/Sources/Xcore/Swift/Components/FeatureFlag/SystemAlert/SystemAlertConfiguration.swift index dd4634330..1d5756433 100644 --- a/Sources/Xcore/Swift/Components/FeatureFlag/SystemAlert/SystemAlertConfiguration.swift +++ b/Sources/Xcore/Swift/Components/FeatureFlag/SystemAlert/SystemAlertConfiguration.swift @@ -32,7 +32,7 @@ import Foundation /// "cta_url": "https://www.example.com" /// } /// ``` -public struct SystemAlertConfiguration: Codable, Hashable, Identifiable { +public struct SystemAlertConfiguration: Hashable, Sendable, Codable, Identifiable { /// A unique id for the system alert. public let id: String diff --git a/Sources/Xcore/Swift/Components/Money/Money+Color.swift b/Sources/Xcore/Swift/Components/Money/Money+Color.swift index ab7f34b7d..c8c920172 100644 --- a/Sources/Xcore/Swift/Components/Money/Money+Color.swift +++ b/Sources/Xcore/Swift/Components/Money/Money+Color.swift @@ -8,7 +8,7 @@ import SwiftUI extension Money { /// A structure representing colors used to format money. - public struct Color: Hashable { + public struct Color: Hashable, Sendable { /// The color for positive values. public let positive: SwiftUI.Color diff --git a/Sources/Xcore/Swift/Components/Money/Money+Font.swift b/Sources/Xcore/Swift/Components/Money/Money+Font.swift index 40cdcfa65..2796a58f8 100644 --- a/Sources/Xcore/Swift/Components/Money/Money+Font.swift +++ b/Sources/Xcore/Swift/Components/Money/Money+Font.swift @@ -8,7 +8,7 @@ import SwiftUI extension Money { /// A structure representing fonts used to format money components. - public struct Font: Hashable { + public struct Font: Hashable, Sendable { /// The font for major unit of the amount. /// /// ```swift @@ -137,7 +137,7 @@ extension Money.Font { extension Money.Font { /// A structure representing font and baseline offset. - public struct Superscript: Hashable { + public struct Superscript: Hashable, Sendable { public let font: UIFont public let baselineOffset: CGFloat diff --git a/Sources/Xcore/Swift/Components/Money/Money+Style.swift b/Sources/Xcore/Swift/Components/Money/Money+Style.swift index cad710123..32d1d4ae9 100644 --- a/Sources/Xcore/Swift/Components/Money/Money+Style.swift +++ b/Sources/Xcore/Swift/Components/Money/Money+Style.swift @@ -8,17 +8,17 @@ import Foundation extension Money { /// A structure representing formatting used to format money components. - public struct Style { + public struct Style: Sendable { public typealias Components = (majorUnit: String, minorUnit: String) public typealias Range = (majorUnit: NSRange?, minorUnit: NSRange?) public let id: Identifier - public let format: (Money) -> String - public let range: (Money) -> Range + public let format: @Sendable (Money) -> String + public let range: @Sendable (Money) -> Range public init( id: Identifier, - format: @escaping (Money) -> String, - range: @escaping (Money) -> Range + format: @escaping @Sendable (Money) -> String, + range: @escaping @Sendable (Money) -> Range ) { self.id = id self.format = format @@ -150,6 +150,7 @@ extension Money.Style { fractionLength: ClosedRange = .defaultFractionDigits, fallback: Self = .default ) -> Self { + @Sendable func canAbbreviate(amount: Decimal) -> Bool { let amount = abs(amount) return amount >= 1000 && amount >= threshold diff --git a/Sources/Xcore/Swift/Components/Money/Money.swift b/Sources/Xcore/Swift/Components/Money/Money.swift index cab50909f..af7ab6c8f 100644 --- a/Sources/Xcore/Swift/Components/Money/Money.swift +++ b/Sources/Xcore/Swift/Components/Money/Money.swift @@ -279,7 +279,7 @@ extension Money { @_disfavoredOverload public func color(_ color: UIColor) -> Self { applying { - $0.color = .init(.init(color)) + $0.color = .init(.init(uiColor: color)) } } @@ -336,7 +336,7 @@ extension Money: ExpressibleByIntegerLiteral { extension Money { /// An enumeration representing the position of currency symbol. - public enum CurrencySymbolPosition: Sendable, Hashable { + public enum CurrencySymbolPosition: Hashable, Sendable { /// Adds currency symbol before the amount (e.g., `$10.00`). case prefix diff --git a/Sources/Xcore/Swift/Components/SelectionType.swift b/Sources/Xcore/Swift/Components/SelectionType.swift index 27c5b908c..3a5fe12a6 100644 --- a/Sources/Xcore/Swift/Components/SelectionType.swift +++ b/Sources/Xcore/Swift/Components/SelectionType.swift @@ -20,6 +20,10 @@ public enum SelectionType { } } +// MARK: - Sendable + +extension SelectionType: Sendable where Value: Sendable {} + // MARK: - Equatable extension SelectionType: Equatable where Value: Equatable { diff --git a/Sources/Xcore/Swift/Components/Transformer/AsyncTransformer.swift b/Sources/Xcore/Swift/Components/Transformer/AsyncTransformer.swift index 88f73e197..e750bfbcb 100644 --- a/Sources/Xcore/Swift/Components/Transformer/AsyncTransformer.swift +++ b/Sources/Xcore/Swift/Components/Transformer/AsyncTransformer.swift @@ -6,13 +6,13 @@ /// A structure representing transformation of an input to an output. @frozen -public struct AsyncTransformer { - private let transform: (Input) async -> Output +public struct AsyncTransformer: Sendable { + private let transform: @Sendable (Input) async -> Output /// An initializer to transform given input. /// /// - Parameter transform: A block to transform the input to an output. - public init(_ transform: @escaping (Input) async -> Output) { + public init(_ transform: @escaping @Sendable (Input) async -> Output) { self.transform = transform } diff --git a/Sources/Xcore/Swift/Components/Transformer/Transformer.swift b/Sources/Xcore/Swift/Components/Transformer/Transformer.swift index 2e38ad876..f2895f35c 100644 --- a/Sources/Xcore/Swift/Components/Transformer/Transformer.swift +++ b/Sources/Xcore/Swift/Components/Transformer/Transformer.swift @@ -6,13 +6,13 @@ /// A structure representing transformation of an input to an output. @frozen -public struct Transformer { - private let transform: (Input) -> Output +public struct Transformer: Sendable { + private let transform: @Sendable (Input) -> Output /// An initializer to transform given input. /// /// - Parameter transform: A block to transform the input to an output. - public init(_ transform: @escaping (Input) -> Output) { + public init(_ transform: @escaping @Sendable (Input) -> Output) { self.transform = transform } diff --git a/Sources/Xcore/Swift/Components/Validation/ValidationRule+Operators.swift b/Sources/Xcore/Swift/Components/Validation/ValidationRule+Operators.swift index 853023505..2595e9fec 100644 --- a/Sources/Xcore/Swift/Components/Validation/ValidationRule+Operators.swift +++ b/Sources/Xcore/Swift/Components/Validation/ValidationRule+Operators.swift @@ -48,7 +48,7 @@ extension ValidationRule { /// - lhs: A value to compare. /// - rhs: Another value to compare. /// - Returns: The validation rule. - public static func &&(lhs: Self, rhs: @autoclosure @escaping () -> Self) -> Self { + public static func &&(lhs: Self, rhs: @autoclosure @escaping @Sendable () -> Self) -> Self { .init { lhs.validate($0) && rhs().validate($0) } } @@ -65,7 +65,7 @@ extension ValidationRule { /// - lhs: A value to compare. /// - rhs: Another value to compare. /// - Returns: The validation rule. - public static func ||(lhs: Self, rhs: @autoclosure @escaping () -> Self) -> Self { + public static func ||(lhs: Self, rhs: @autoclosure @escaping @Sendable () -> Self) -> Self { .init { lhs.validate($0) || rhs().validate($0) } } diff --git a/Sources/Xcore/Swift/Components/Validation/ValidationRule.swift b/Sources/Xcore/Swift/Components/Validation/ValidationRule.swift index 38103aed0..b383e8e03 100644 --- a/Sources/Xcore/Swift/Components/Validation/ValidationRule.swift +++ b/Sources/Xcore/Swift/Components/Validation/ValidationRule.swift @@ -6,10 +6,10 @@ import Foundation -public struct ValidationRule { - private let block: (Input) -> Bool +public struct ValidationRule: Sendable { + private let block: @Sendable (Input) -> Bool - public init(_ block: @escaping (Input) -> Bool) { + public init(_ block: @escaping @Sendable (Input) -> Bool) { self.block = block } diff --git a/Sources/Xcore/Swift/Extensions/Numbers/CustomFloatingPointFormatStyle.swift b/Sources/Xcore/Swift/Extensions/Numbers/CustomFloatingPointFormatStyle.swift index 76f212966..0d630c64b 100644 --- a/Sources/Xcore/Swift/Extensions/Numbers/CustomFloatingPointFormatStyle.swift +++ b/Sources/Xcore/Swift/Extensions/Numbers/CustomFloatingPointFormatStyle.swift @@ -10,7 +10,7 @@ import Foundation extension CustomFloatingPointFormatStyle { /// An enumeration representing the type of formatting. - public enum Kind: Codable, Hashable { + public enum Kind: Hashable, Sendable, Codable { /// Formats as a number. case number @@ -21,7 +21,7 @@ extension CustomFloatingPointFormatStyle { case percent(scale: PercentageScale) /// An enumeration representing the scale of percent formatting. - public enum PercentageScale: Codable, Hashable, Sendable { + public enum PercentageScale: Sendable, Hashable, Codable { /// Percentage scale is: `0.0 - 1.0`. case zeroToOne @@ -35,7 +35,7 @@ extension CustomFloatingPointFormatStyle { /// A structure that creates a locale-appropriate string representation of a /// double and decimal instance. -public struct CustomFloatingPointFormatStyle: Codable, Hashable, MutableAppliable { +public struct CustomFloatingPointFormatStyle: Hashable, Sendable, Codable, MutableAppliable { public let type: Kind public var locale: Locale = .numbers public var sign: SignedNumericSign = .default diff --git a/Sources/Xcore/Swift/Extensions/Numbers/SignedNumericSign.swift b/Sources/Xcore/Swift/Extensions/Numbers/SignedNumericSign.swift index 1fa0acb34..01b1c844d 100644 --- a/Sources/Xcore/Swift/Extensions/Numbers/SignedNumericSign.swift +++ b/Sources/Xcore/Swift/Extensions/Numbers/SignedNumericSign.swift @@ -7,7 +7,7 @@ import Foundation /// A structure representing signs (+/−) used to format signed numeric types. -public struct SignedNumericSign: Sendable, Codable, Hashable { +public struct SignedNumericSign: Hashable, Sendable, Codable { /// The string used to represent sign for positive values. public let positive: String diff --git a/Sources/Xcore/Swift/Extensions/URL/URL+Extensions.swift b/Sources/Xcore/Swift/Extensions/URL/URL+Extensions.swift index 27fe4b0a5..e39983ea4 100644 --- a/Sources/Xcore/Swift/Extensions/URL/URL+Extensions.swift +++ b/Sources/Xcore/Swift/Extensions/URL/URL+Extensions.swift @@ -300,7 +300,7 @@ extension URL { } extension URL { - public struct Scheme: RawRepresentable, Hashable, CustomStringConvertible { + public struct Scheme: RawRepresentable, Hashable, Sendable, CustomStringConvertible { public let rawValue: String public init(rawValue: String) { diff --git a/Sources/Xcore/Swift/PropertyWrappers/Percentage.swift b/Sources/Xcore/Swift/PropertyWrappers/Percentage.swift index 918efe44d..b794f3c2b 100644 --- a/Sources/Xcore/Swift/PropertyWrappers/Percentage.swift +++ b/Sources/Xcore/Swift/PropertyWrappers/Percentage.swift @@ -23,7 +23,7 @@ import Foundation /// sliderValue -= 1 /// // print(sliderValue) // 99.0% /// ``` -public struct Percentage: RawRepresentable { +public struct Percentage: RawRepresentable, Sendable { public static let min: Percentage = 0 public static let max: Percentage = 100 diff --git a/Sources/Xcore/Swift/Protocols/DoubleOrDecimalProtocol.swift b/Sources/Xcore/Swift/Protocols/DoubleOrDecimalProtocol.swift index ac6fdc24d..a0425b773 100644 --- a/Sources/Xcore/Swift/Protocols/DoubleOrDecimalProtocol.swift +++ b/Sources/Xcore/Swift/Protocols/DoubleOrDecimalProtocol.swift @@ -8,7 +8,7 @@ import Foundation /// A type that represents either a `Double` or a `Decimal` floating-point value /// type. -public protocol DoubleOrDecimalProtocol: SignedNumeric, Comparable, Hashable, Codable, ExpressibleByFloatLiteral { +public protocol DoubleOrDecimalProtocol: SignedNumeric, Comparable, Hashable, Codable, ExpressibleByFloatLiteral, Sendable { var nsNumber: NSNumber { get } /// A Boolean property indicating whether the fractional part of the decimal is