Skip to content

Commit

Permalink
Added Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
zmian committed Feb 12, 2024
1 parent 7ff09d7 commit 12c6f4f
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions Sources/Xcore/Swift/Components/ElementPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

public struct ElementPosition: OptionSet {
public struct ElementPosition: OptionSet, Sendable {
public let rawValue: Int

public init(rawValue: Int) {
Expand All @@ -21,7 +21,7 @@ public struct ElementPosition: OptionSet {

// MARK: - ButtonIdentifier

public enum ButtonIdentifierTag {}
public enum ButtonIdentifierTag: Sendable {}
public typealias ButtonIdentifier = Identifier<ButtonIdentifierTag>

extension ButtonIdentifier {
Expand All @@ -32,15 +32,15 @@ extension ButtonIdentifier {

// MARK: - ButtonState

public enum ButtonState {
public enum ButtonState: Sendable {
case normal
case pressed
case disabled
}

// MARK: - ButtonProminence

public enum ButtonProminence {
public enum ButtonProminence: Sendable {
case fill
case outline
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Sources/Xcore/Swift/Components/Money/Money+Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Sources/Xcore/Swift/Components/Money/Money+Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions Sources/Xcore/Swift/Components/Money/Money+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>
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<Self>,
format: @escaping (Money) -> String,
range: @escaping (Money) -> Range
format: @escaping @Sendable (Money) -> String,
range: @escaping @Sendable (Money) -> Range
) {
self.id = id
self.format = format
Expand Down Expand Up @@ -150,6 +150,7 @@ extension Money.Style {
fractionLength: ClosedRange<Int> = .defaultFractionDigits,
fallback: Self = .default
) -> Self {
@Sendable
func canAbbreviate(amount: Decimal) -> Bool {
let amount = abs(amount)
return amount >= 1000 && amount >= threshold
Expand Down
4 changes: 2 additions & 2 deletions Sources/Xcore/Swift/Components/Money/Money.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Sources/Xcore/Swift/Components/SelectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public enum SelectionType<Value> {
}
}

// MARK: - Sendable

extension SelectionType: Sendable where Value: Sendable {}

// MARK: - Equatable

extension SelectionType: Equatable where Value: Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

/// A structure representing transformation of an input to an output.
@frozen
public struct AsyncTransformer<Input, Output> {
private let transform: (Input) async -> Output
public struct AsyncTransformer<Input, Output>: 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
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Xcore/Swift/Components/Transformer/Transformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

/// A structure representing transformation of an input to an output.
@frozen
public struct Transformer<Input, Output> {
private let transform: (Input) -> Output
public struct Transformer<Input, Output>: 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand All @@ -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) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import Foundation

public struct ValidationRule<Input> {
private let block: (Input) -> Bool
public struct ValidationRule<Input>: Sendable {
private let block: @Sendable (Input) -> Bool

public init(_ block: @escaping (Input) -> Bool) {
public init(_ block: @escaping @Sendable (Input) -> Bool) {
self.block = block
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -35,7 +35,7 @@ extension CustomFloatingPointFormatStyle {

/// A structure that creates a locale-appropriate string representation of a
/// double and decimal instance.
public struct CustomFloatingPointFormatStyle<Value: DoubleOrDecimalProtocol>: Codable, Hashable, MutableAppliable {
public struct CustomFloatingPointFormatStyle<Value: DoubleOrDecimalProtocol>: Hashable, Sendable, Codable, MutableAppliable {
public let type: Kind
public var locale: Locale = .numbers
public var sign: SignedNumericSign = .default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Sources/Xcore/Swift/Extensions/URL/URL+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Xcore/Swift/PropertyWrappers/Percentage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12c6f4f

Please sign in to comment.