diff --git a/.swift-format b/.swift-format index 97c15060..de7680fb 100644 --- a/.swift-format +++ b/.swift-format @@ -5,7 +5,7 @@ }, "maximumBlankLines": 1, "indentConditionalCompilationBlocks": false, - "rules": { - "AllPublicDeclarationsHaveDocumentation": false - } + "lineBreakBeforeEachArgument": true, + "lineBreakBeforeEachGenericRequirement": true, + "respectsExistingLineBreaks": false } \ No newline at end of file diff --git a/DevelopmentDependencies/Package.resolved b/DevelopmentDependencies/Package.resolved index 4b368bf9..f163931d 100644 --- a/DevelopmentDependencies/Package.resolved +++ b/DevelopmentDependencies/Package.resolved @@ -6,17 +6,17 @@ "repositoryURL": "https://github.com/apple/swift-argument-parser.git", "state": { "branch": null, - "revision": "223d62adc52d51669ae2ee19bdb8b7d9fd6fcd9c", - "version": "0.0.6" + "revision": "986d191f94cec88f6350056da59c2e59e83d1229", + "version": "0.4.3" } }, { "package": "swift-format", "repositoryURL": "https://github.com/apple/swift-format.git", "state": { - "branch": "swift-5.2-branch", - "revision": "07e082b100dd14439b11451c24796999ff3ef928", - "version": null + "branch": null, + "revision": "9c15831b798d767c9af0927a931de5d557004936", + "version": "0.50400.0" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/apple/swift-syntax", "state": { "branch": null, - "revision": "0688b9cfc4c3dd234e4f55f1f056b2affc849873", - "version": "0.50200.0" + "revision": "2fff9fc25cdc059379b6bd309377cfab45d8520c", + "version": "0.50400.0" } }, { @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/mxcl/Version.git", "state": { "branch": null, - "revision": "200046c93f6d5d78a6d72bfd9c0b27a95e9c0a2b", - "version": "1.2.0" + "revision": "1fe824b80d89201652e7eca7c9252269a1d85e25", + "version": "2.0.1" } }, { @@ -42,7 +42,7 @@ "repositoryURL": "https://github.com/JosephDuffy/xcutils.git", "state": { "branch": "master", - "revision": "c89ab37a15ec5c93f954b50b0259d784fbd6c46e", + "revision": "c20c11190446042792c798d2fa73559330864673", "version": null } } diff --git a/DevelopmentDependencies/Package.swift b/DevelopmentDependencies/Package.swift index 468d4ece..279659ad 100644 --- a/DevelopmentDependencies/Package.swift +++ b/DevelopmentDependencies/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.2 +// swift-tools-version:5.4 import PackageDescription let package = Package( @@ -8,7 +8,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/JosephDuffy/xcutils.git", .branch("master")), - .package(url: "https://github.com/apple/swift-format.git", .branch("swift-5.2-branch")), + .package(url: "https://github.com/apple/swift-format.git", .exact("0.50400.0")), ], targets: [ .target(name: "DevelopmentDependencies"), diff --git a/Sources/GatheredKit/Action/Action.swift b/Sources/GatheredKit/Action/Action.swift index 740391c0..2650c42b 100644 --- a/Sources/GatheredKit/Action/Action.swift +++ b/Sources/GatheredKit/Action/Action.swift @@ -6,18 +6,12 @@ public struct Action { private let performClosure: () -> Void - public init( - title: String, - isAvailable: Bool, - perform: @escaping () -> Void - ) { + public init(title: String, isAvailable: Bool, perform: @escaping () -> Void) { self.title = title self.isAvailable = isAvailable self.performClosure = perform } - public func perform() { - performClosure() - } + public func perform() { performClosure() } } diff --git a/Sources/GatheredKit/Controllable/CustomisableUpdateIntervalControllable.swift b/Sources/GatheredKit/Controllable/CustomisableUpdateIntervalControllable.swift index 038035a9..bd0bf877 100644 --- a/Sources/GatheredKit/Controllable/CustomisableUpdateIntervalControllable.swift +++ b/Sources/GatheredKit/Controllable/CustomisableUpdateIntervalControllable.swift @@ -27,8 +27,6 @@ extension CustomisableUpdateIntervalControllable { Starts performing period updated. The value of the static variable `defaultUpdateInterval` will used for the update interval. */ - public func startUpdating() { - startUpdating(every: type(of: self).defaultUpdateInterval) - } + public func startUpdating() { startUpdating(every: type(of: self).defaultUpdateInterval) } } diff --git a/Sources/GatheredKit/Extensions/String+localized.swift b/Sources/GatheredKit/Extensions/String+localized.swift index 9187d9c6..7771757a 100644 --- a/Sources/GatheredKit/Extensions/String+localized.swift +++ b/Sources/GatheredKit/Extensions/String+localized.swift @@ -4,9 +4,7 @@ extension String { var localized: String { let appLocalizedString = NSLocalizedString(self, comment: "") - guard appLocalizedString == self else { - return appLocalizedString - } + guard appLocalizedString == self else { return appLocalizedString } let frameworkBundle = Bundle(for: FrameworkClass.self) return NSLocalizedString(self, bundle: frameworkBundle, comment: "") diff --git a/Sources/GatheredKit/Extensions/castToOptional.swift b/Sources/GatheredKit/Extensions/castToOptional.swift index 156d4393..be05ad86 100644 --- a/Sources/GatheredKit/Extensions/castToOptional.swift +++ b/Sources/GatheredKit/Extensions/castToOptional.swift @@ -1,24 +1,21 @@ /// Casts the provided value to `Any?` -/// +/// /// This method is required because casting an `Any` to `Any?` wraps the original `Any` /// in an `Optional`, producing an `Any??`. -/// +/// /// To get around this issue if the value passed is actually optional it is matched against /// the `Optional` case `some`, and the wrapped value is returned, wrapped in an `Optional`, allowing /// the compiler to correctly treat it as an `Any?`. -/// +/// /// If the passed value is not an `Optional` it is wrapped in an `Optional` for concistency. -/// +/// /// - parameter value: The value to be cast to `Any?` /// - returns: The provided value cast to `Any?` internal func castToOptional(_ value: Any) -> Any? { // swiftlint:disable syntactic_sugar switch value { - case Optional.some(let value): - return Optional(value) - case Optional.none: - return nil - default: - return Optional(value) + case Optional.some(let value): return Optional(value) + case Optional.none: return nil + default: return Optional(value) } } diff --git a/Sources/GatheredKit/Properties/Measurements/AccelerationProperty.swift b/Sources/GatheredKit/Properties/Measurements/AccelerationProperty.swift index 153896eb..666bc59b 100644 --- a/Sources/GatheredKit/Properties/Measurements/AccelerationProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/AccelerationProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> AccelerationProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func acceleration( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAccelerationProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func metersPerSecondSquared( @@ -34,8 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> AccelerationProperty { return .init( - displayName: displayName, value: value, unit: .metersPerSecondSquared, - formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .metersPerSecondSquared, + formatter: formatter, + date: date + ) } public static func metersPerSecondSquared( @@ -45,8 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAccelerationProperty { return .init( - displayName: displayName, value: value, unit: .metersPerSecondSquared, - formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .metersPerSecondSquared, + formatter: formatter, + date: date + ) } public static func gravity( @@ -56,7 +74,11 @@ extension AnyProperty { date: Date = Date() ) -> AccelerationProperty { return .init( - displayName: displayName, value: value, unit: .gravity, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .gravity, + formatter: formatter, + date: date ) } @@ -67,7 +89,11 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAccelerationProperty { return .init( - displayName: displayName, value: value, unit: .gravity, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .gravity, + formatter: formatter, + date: date ) } diff --git a/Sources/GatheredKit/Properties/Measurements/AngleProperty.swift b/Sources/GatheredKit/Properties/Measurements/AngleProperty.swift index c20adeea..16fa2fc0 100644 --- a/Sources/GatheredKit/Properties/Measurements/AngleProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/AngleProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> AngleProperty { return AngleProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func angle( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAngleProperty { return OptionalAngleProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func degrees( @@ -34,7 +44,11 @@ extension AnyProperty { date: Date = Date() ) -> AngleProperty { return AngleProperty( - displayName: displayName, value: value, unit: .degrees, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .degrees, + formatter: formatter, + date: date ) } @@ -45,7 +59,11 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAngleProperty { return OptionalAngleProperty( - displayName: displayName, value: value, unit: .degrees, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .degrees, + formatter: formatter, + date: date ) } @@ -56,7 +74,11 @@ extension AnyProperty { date: Date = Date() ) -> AngleProperty { return .init( - displayName: displayName, value: value, unit: .radians, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .radians, + formatter: formatter, + date: date ) } @@ -67,7 +89,11 @@ extension AnyProperty { date: Date = Date() ) -> OptionalAngleProperty { return .init( - displayName: displayName, value: value, unit: .radians, formatter: formatter, date: date + displayName: displayName, + value: value, + unit: .radians, + formatter: formatter, + date: date ) } diff --git a/Sources/GatheredKit/Properties/Measurements/FrequencyProperty.swift b/Sources/GatheredKit/Properties/Measurements/FrequencyProperty.swift index 9f5c1c1a..86691f52 100644 --- a/Sources/GatheredKit/Properties/Measurements/FrequencyProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/FrequencyProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> FrequencyProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func frequency( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalFrequencyProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func radiansPerSecond( @@ -34,8 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> FrequencyProperty { return .init( - displayName: displayName, value: value, unit: .radiansPerSecond, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .radiansPerSecond, + formatter: formatter, + date: date + ) } public static func radiansPerSecond( @@ -45,8 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalFrequencyProperty { return .init( - displayName: displayName, value: value, unit: .radiansPerSecond, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .radiansPerSecond, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Properties/Measurements/LengthProperty.swift b/Sources/GatheredKit/Properties/Measurements/LengthProperty.swift index 094de45d..eabd7774 100644 --- a/Sources/GatheredKit/Properties/Measurements/LengthProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/LengthProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> LengthProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func length( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalLengthProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func meters( @@ -34,7 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> LengthProperty { return .init( - displayName: displayName, value: value, unit: .meters, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .meters, + formatter: formatter, + date: date + ) } public static func meters( @@ -44,7 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalLengthProperty { return .init( - displayName: displayName, value: value, unit: .meters, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .meters, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Properties/Measurements/MagneticFieldProperty.swift b/Sources/GatheredKit/Properties/Measurements/MagneticFieldProperty.swift index 090e4a0a..d56214d5 100644 --- a/Sources/GatheredKit/Properties/Measurements/MagneticFieldProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/MagneticFieldProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> MagneticFieldProperty { return MagneticFieldProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func magneticField( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalMagneticFieldProperty { return OptionalMagneticFieldProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func tesla( @@ -34,7 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> MagneticFieldProperty { return MagneticFieldProperty( - displayName: displayName, value: value, unit: .tesla, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .tesla, + formatter: formatter, + date: date + ) } public static func tesla( @@ -44,7 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalMagneticFieldProperty { return OptionalMagneticFieldProperty( - displayName: displayName, value: value, unit: .tesla, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: .tesla, + formatter: formatter, + date: date + ) } public static func microTesla( @@ -54,8 +74,12 @@ extension AnyProperty { date: Date = Date() ) -> MagneticFieldProperty { return MagneticFieldProperty( - displayName: displayName, value: value, unit: .microTesla, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .microTesla, + formatter: formatter, + date: date + ) } public static func microTesla( @@ -65,8 +89,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalMagneticFieldProperty { return OptionalMagneticFieldProperty( - displayName: displayName, value: value, unit: .microTesla, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .microTesla, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Properties/Measurements/MeasurementProperty.swift b/Sources/GatheredKit/Properties/Measurements/MeasurementProperty.swift index 1bb046c0..0d7a3084 100644 --- a/Sources/GatheredKit/Properties/Measurements/MeasurementProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/MeasurementProperty.swift @@ -9,25 +9,17 @@ public final class MeasurementProperty: UpdatableProperty } public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty> { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty> { asReadOnlyProperty } // MARK: `Property` Requirements /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A human-friendly display name that describes the property. @@ -45,17 +37,11 @@ public final class MeasurementProperty: UpdatableProperty // MARK: Measurement Properties - public var measurement: Measurement { - return value - } + public var measurement: Measurement { return value } - public var unit: Unit { - return measurement.unit - } + public var unit: Unit { return measurement.unit } - public var measuredValue: Double { - return measurement.value - } + public var measuredValue: Double { return measurement.value } // MARK: Initialisers @@ -80,26 +66,26 @@ public final class MeasurementProperty: UpdatableProperty ) { let measurement = Measurement(value: value, unit: unit) self.init( - displayName: displayName, measurement: measurement, formatter: formatter, date: date) + displayName: displayName, + measurement: measurement, + formatter: formatter, + date: date + ) } // MARK: Update Functions - @discardableResult - public func updateValue( - _ value: Measurement, - date: Date - ) -> Snapshot { + @discardableResult public func updateValue(_ value: Measurement, date: Date) -> Snapshot< + Value + > { let snapshot = Snapshot(value: value, date: date) self.snapshot = snapshot return snapshot } - @discardableResult - public func updateMeasuredValue( - _ measuredValue: Double, - date: Date = Date() - ) -> Snapshot { + @discardableResult public func updateMeasuredValue(_ measuredValue: Double, date: Date = Date()) + -> Snapshot + { let measurement = Measurement(value: measuredValue, unit: self.measurement.unit) return updateValue(measurement, date: date) } @@ -111,8 +97,10 @@ public final class MeasurementProperty: UpdatableProperty - Parameter date: The date and time the `value` was recorded. Defaults to the current date and time. - Returns: The new snapshot, or `nil` if the value was not different. */ - @discardableResult - public func updateMeasuredValueIfDifferent(_ measuredValue: Double, date: Date = Date()) -> Snapshot? { + @discardableResult public func updateMeasuredValueIfDifferent( + _ measuredValue: Double, + date: Date = Date() + ) -> Snapshot? { guard measuredValue != self.measuredValue else { return nil } return updateMeasuredValue(measuredValue, date: date) } diff --git a/Sources/GatheredKit/Properties/Measurements/OptionalMeasurementProperty.swift b/Sources/GatheredKit/Properties/Measurements/OptionalMeasurementProperty.swift index e3a78d0a..7b9b9954 100644 --- a/Sources/GatheredKit/Properties/Measurements/OptionalMeasurementProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/OptionalMeasurementProperty.swift @@ -1,22 +1,18 @@ import Foundation @propertyWrapper -public final class OptionalMeasurementProperty: UpdatableProperty, Equatable { +public final class OptionalMeasurementProperty: UpdatableProperty, Equatable +{ public typealias Value = Measurement? public static func == ( - lhs: OptionalMeasurementProperty, rhs: OptionalMeasurementProperty - ) -> Bool { - lhs.displayName == rhs.displayName && lhs.snapshot == rhs.snapshot - } + lhs: OptionalMeasurementProperty, + rhs: OptionalMeasurementProperty + ) -> Bool { lhs.displayName == rhs.displayName && lhs.snapshot == rhs.snapshot } public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty> { @@ -27,9 +23,7 @@ public final class OptionalMeasurementProperty: Updatable /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A human-friendly display name that describes the property. @@ -47,15 +41,11 @@ public final class OptionalMeasurementProperty: Updatable // MARK: Measurement Properties - public var measurement: Value { - return value - } + public var measurement: Value { return value } public private(set) var unit: Unit - public var measuredValue: Double? { - return measurement?.value - } + public var measuredValue: Double? { return measurement?.value } // MARK: Initialisers @@ -95,8 +85,7 @@ public final class OptionalMeasurementProperty: Updatable // MARK: Update Functions - @discardableResult - public func updateValue( + @discardableResult public func updateValue( _ measurement: Measurement?, date: Date = Date() ) -> Snapshot { @@ -105,8 +94,7 @@ public final class OptionalMeasurementProperty: Updatable return snapshot } - @discardableResult - public func updateMeasuredValue( + @discardableResult public func updateMeasuredValue( _ measuredValue: Double?, date: Date = Date() ) -> Snapshot { @@ -124,8 +112,10 @@ public final class OptionalMeasurementProperty: Updatable - Parameter date: The date and time the `value` was recorded. Defaults to the current date and time. - Returns: The new snapshot, or `nil` if the value was not different. */ - @discardableResult - public func updateMeasuredValueIfDifferent(_ measuredValue: Double?, date: Date = Date()) -> Snapshot? { + @discardableResult public func updateMeasuredValueIfDifferent( + _ measuredValue: Double?, + date: Date = Date() + ) -> Snapshot? { guard measuredValue != measurement?.value else { return nil } return updateMeasuredValue(measuredValue, date: date) } @@ -140,7 +130,11 @@ extension OptionalMeasurementProperty where Unit: Foundation.Dimension { date: Date = Date() ) { self.init( - displayName: displayName, value: measuredValue, unit: dimention, formatter: formatter, - date: date) + displayName: displayName, + value: measuredValue, + unit: dimention, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Properties/Measurements/PressureProperty.swift b/Sources/GatheredKit/Properties/Measurements/PressureProperty.swift index 12d5f08c..bb1f5eeb 100644 --- a/Sources/GatheredKit/Properties/Measurements/PressureProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/PressureProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> PressureProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func pressure( @@ -24,7 +29,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalPressureProperty { return .init( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func kilopascals( @@ -34,8 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> PressureProperty { return .init( - displayName: displayName, value: value, unit: .kilopascals, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .kilopascals, + formatter: formatter, + date: date + ) } public static func kilopascals( @@ -45,8 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalPressureProperty { return .init( - displayName: displayName, value: value, unit: .kilopascals, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .kilopascals, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Properties/Measurements/SpeedProperty.swift b/Sources/GatheredKit/Properties/Measurements/SpeedProperty.swift index 91024463..74f89bd0 100644 --- a/Sources/GatheredKit/Properties/Measurements/SpeedProperty.swift +++ b/Sources/GatheredKit/Properties/Measurements/SpeedProperty.swift @@ -13,7 +13,12 @@ extension AnyProperty { date: Date = Date() ) -> SpeedProperty { return SpeedProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func metersPerSecond( @@ -23,8 +28,12 @@ extension AnyProperty { date: Date = Date() ) -> SpeedProperty { return SpeedProperty( - displayName: displayName, value: value, unit: .metersPerSecond, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .metersPerSecond, + formatter: formatter, + date: date + ) } public static func speed( @@ -35,7 +44,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalSpeedProperty { return OptionalSpeedProperty( - displayName: displayName, value: value, unit: unit, formatter: formatter, date: date) + displayName: displayName, + value: value, + unit: unit, + formatter: formatter, + date: date + ) } public static func metersPerSecond( @@ -45,8 +59,12 @@ extension AnyProperty { date: Date = Date() ) -> OptionalSpeedProperty { return OptionalSpeedProperty( - displayName: displayName, value: value, unit: .metersPerSecond, formatter: formatter, - date: date) + displayName: displayName, + value: value, + unit: .metersPerSecond, + formatter: formatter, + date: date + ) } } diff --git a/Sources/GatheredKit/Property/BasicProperty.swift b/Sources/GatheredKit/Property/BasicProperty.swift index d5fbf215..b4a65e96 100644 --- a/Sources/GatheredKit/Property/BasicProperty.swift +++ b/Sources/GatheredKit/Property/BasicProperty.swift @@ -1,14 +1,10 @@ import Foundation -@propertyWrapper -public final class BasicProperty: UpdatableProperty where Formatter: Foundation.Formatter { +@propertyWrapper public final class BasicProperty: UpdatableProperty +where Formatter: Foundation.Formatter { public var wrappedValue: Value { - get { - return value - } - set { - value = newValue - } + get { return value } + set { value = newValue } } public var projectedValue: ReadOnlyProperty> { @@ -22,19 +18,13 @@ public final class BasicProperty: UpdatableProperty where Form /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// The current value of the property. public internal(set) var value: Value { - get { - return snapshot.value - } - set { - snapshot = Snapshot(value: newValue, date: Date()) - } + get { return snapshot.value } + set { snapshot = Snapshot(value: newValue, date: Date()) } } /// A formatter that can be used to build a human-friendly string from the @@ -50,7 +40,10 @@ public final class BasicProperty: UpdatableProperty where Form // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -67,11 +60,7 @@ public final class BasicProperty: UpdatableProperty where Form - parameter date: The date and time the `value` was recorded. Defaults to the current date and time. - Returns: The new snapshot. */ - @discardableResult - public func updateValue( - _ value: Value, - date: Date - ) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { let snapshot = Snapshot(value: value, date: date) self.snapshot = snapshot return snapshot @@ -80,10 +69,10 @@ public final class BasicProperty: UpdatableProperty where Form extension BasicProperty: Equatable where Value: Equatable { public static func == ( - lhs: BasicProperty, rhs: BasicProperty + lhs: BasicProperty, + rhs: BasicProperty ) -> Bool { - return - lhs.displayName == rhs.displayName && lhs.value == rhs.value && lhs.date == rhs.date + return lhs.displayName == rhs.displayName && lhs.value == rhs.value && lhs.date == rhs.date } } diff --git a/Sources/GatheredKit/Property/Property.swift b/Sources/GatheredKit/Property/Property.swift index ed8b4e3f..164b0662 100644 --- a/Sources/GatheredKit/Property/Property.swift +++ b/Sources/GatheredKit/Property/Property.swift @@ -13,33 +13,21 @@ public protocol Property: AnyProperty { extension Property { - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } - public var value: Value { - return snapshot.value - } + public var value: Value { return snapshot.value } /// The date of the latest value. - public var date: Date { - return snapshot.date - } + public var date: Date { return snapshot.date } /// The type-erased current value of the property. - public var typeErasedValue: Any? { - return snapshot.value - } + public var typeErasedValue: Any? { return snapshot.value } /// A type-erased formatter that can be used to build a human-friendly /// string from the value. - public var typeErasedFormatter: Foundation.Formatter { - return formatter - } + public var typeErasedFormatter: Foundation.Formatter { return formatter } - public var asReadOnlyProperty: ReadOnlyProperty { - return ReadOnlyProperty(self) - } + public var asReadOnlyProperty: ReadOnlyProperty { return ReadOnlyProperty(self) } public var typeErasedUpdatePublisher: AnyUpdatePublisher { return updatePublisher.map { $0 as AnySnapshot }.eraseToAnyUpdatePublisher() diff --git a/Sources/GatheredKit/Property/ReadOnlyProperty.swift b/Sources/GatheredKit/Property/ReadOnlyProperty.swift index 2392eeae..c0bd8738 100644 --- a/Sources/GatheredKit/Property/ReadOnlyProperty.swift +++ b/Sources/GatheredKit/Property/ReadOnlyProperty.swift @@ -1,33 +1,22 @@ import Foundation -@dynamicMemberLookup -public final class ReadOnlyProperty: AnyProperty { +@dynamicMemberLookup public final class ReadOnlyProperty: AnyProperty { - public var displayName: String { - wrapped.displayName - } + public var displayName: String { wrapped.displayName } - public var date: Date { - wrapped.date - } + public var date: Date { wrapped.date } - public var typeErasedFormatter: Foundation.Formatter { - wrapped.typeErasedFormatter - } + public var typeErasedFormatter: Foundation.Formatter { wrapped.typeErasedFormatter } public var typeErasedUpdatePublisher: AnyUpdatePublisher { wrapped.typeErasedUpdatePublisher } - public var typeErasedValue: Any? { - wrapped.typeErasedValue - } + public var typeErasedValue: Any? { wrapped.typeErasedValue } private let wrapped: Property - init(_ wrapped: Property) { - self.wrapped = wrapped - } + init(_ wrapped: Property) { self.wrapped = wrapped } public subscript(dynamicMember keyPath: KeyPath) -> Value { return wrapped[keyPath: keyPath] @@ -35,7 +24,5 @@ public final class ReadOnlyProperty: AnyProperty { } extension ReadOnlyProperty: PropertiesProvider where Property: PropertiesProvider { - public var allProperties: [AnyProperty] { - wrapped.allProperties - } + public var allProperties: [AnyProperty] { wrapped.allProperties } } diff --git a/Sources/GatheredKit/Property/Snapshot.swift b/Sources/GatheredKit/Property/Snapshot.swift index 01c6a584..3ee8fe07 100644 --- a/Sources/GatheredKit/Property/Snapshot.swift +++ b/Sources/GatheredKit/Property/Snapshot.swift @@ -7,9 +7,7 @@ public struct Snapshot: AnySnapshot { /// The date the `value` was captured. public let date: Date - public var typeErasedValue: Any? { - return castToOptional(value) - } + public var typeErasedValue: Any? { return castToOptional(value) } /** Create a new snapshot with the provided value and date. diff --git a/Sources/GatheredKit/Property/UpdatableProperty.swift b/Sources/GatheredKit/Property/UpdatableProperty.swift index e3043abf..01704e31 100644 --- a/Sources/GatheredKit/Property/UpdatableProperty.swift +++ b/Sources/GatheredKit/Property/UpdatableProperty.swift @@ -8,8 +8,7 @@ public protocol UpdatableProperty: Property { - Parameter date: The date and time the `value` was recorded. Defaults to the current date and time. - Returns: The new snapshot. */ - @discardableResult - func updateValue(_ value: Value, date: Date) -> Snapshot + @discardableResult func updateValue(_ value: Value, date: Date) -> Snapshot } extension UpdatableProperty { @@ -20,8 +19,7 @@ extension UpdatableProperty { - Parameter value: The new value of the property. - Returns: The new snapshot. */ - @discardableResult - public func updateValue(_ value: Value) -> Snapshot { + @discardableResult public func updateValue(_ value: Value) -> Snapshot { updateValue(value, date: Date()) } } @@ -34,8 +32,9 @@ extension UpdatableProperty where Value: Equatable { - Parameter date: The date and time the `value` was recorded. Defaults to the current date and time. - Returns: The new snapshot, or `nil` if the value was not different. */ - @discardableResult - public func updateValueIfDifferent(_ value: Value, date: Date = Date()) -> Snapshot? { + @discardableResult public func updateValueIfDifferent(_ value: Value, date: Date = Date()) + -> Snapshot? + { guard value != self.value else { return nil } return updateValue(value, date: date) } diff --git a/Sources/GatheredKit/Source/BasePollingSource.swift b/Sources/GatheredKit/Source/BasePollingSource.swift index c5b76214..96574b8f 100644 --- a/Sources/GatheredKit/Source/BasePollingSource.swift +++ b/Sources/GatheredKit/Source/BasePollingSource.swift @@ -13,29 +13,21 @@ open class BasePollingSource: UpdatingSource { case monitoring(updatesQueue: DispatchQueue, updateInterval: TimeInterval?) } - open var availability: SourceAvailability { - return .available - } + open var availability: SourceAvailability { return .available } - open var name: String { - return "" - } + open var name: String { return "" } public final var updateInterval: TimeInterval? { switch state { - case .monitoring(_, let updateInterval): - return updateInterval - case .notMonitoring: - return nil + case .monitoring(_, let updateInterval): return updateInterval + case .notMonitoring: return nil } } public var isUpdating: Bool { switch state { - case .notMonitoring: - return false - case .monitoring: - return true + case .notMonitoring: return false + case .monitoring: return true } } @@ -51,10 +43,8 @@ open class BasePollingSource: UpdatingSource { private var updatesQueue: DispatchQueue? { switch state { - case .monitoring(let updatesQueue, _): - return updatesQueue - case .notMonitoring: - return nil + case .monitoring(let updatesQueue, _): return updatesQueue + case .notMonitoring: return nil } } @@ -70,9 +60,7 @@ open class BasePollingSource: UpdatingSource { extension CustomisableUpdateIntervalControllable where Self: BasePollingSource, Self: ManuallyUpdatablePropertiesProvider { - public func stopUpdating() { - state = .notMonitoring - } + public func stopUpdating() { state = .notMonitoring } } diff --git a/Sources/GatheredKit/SourceProvider/SingleSourceProvider.swift b/Sources/GatheredKit/SourceProvider/SingleSourceProvider.swift index 6f794809..98f63e84 100644 --- a/Sources/GatheredKit/SourceProvider/SingleSourceProvider.swift +++ b/Sources/GatheredKit/SourceProvider/SingleSourceProvider.swift @@ -1,16 +1,10 @@ /// A source provider that contains a single source public final class SingleSourceProvider: SourceProvider { - public var name: String { - return source.name - } + public var name: String { return source.name } - public var sources: [Source] { - return [source] - } + public var sources: [Source] { return [source] } public let source: Source - public init(source: Source) { - self.source = source - } + public init(source: Source) { self.source = source } } diff --git a/Sources/GatheredKit/SourceProvider/SourceProvider.swift b/Sources/GatheredKit/SourceProvider/SourceProvider.swift index bf428b30..cb4a58d9 100644 --- a/Sources/GatheredKit/SourceProvider/SourceProvider.swift +++ b/Sources/GatheredKit/SourceProvider/SourceProvider.swift @@ -5,8 +5,4 @@ public protocol SourceProvider: AnySourceProvider { var sources: [ProvidedSource] { get } } -extension SourceProvider { - public var typeErasedSources: [Source] { - return sources - } -} +extension SourceProvider { public var typeErasedSources: [Source] { return sources } } diff --git a/Sources/GatheredKit/SourceProvider/UpdatingSourceProvider.swift b/Sources/GatheredKit/SourceProvider/UpdatingSourceProvider.swift index f3f7b9d6..5f9233a0 100644 --- a/Sources/GatheredKit/SourceProvider/UpdatingSourceProvider.swift +++ b/Sources/GatheredKit/SourceProvider/UpdatingSourceProvider.swift @@ -1,19 +1,17 @@ public protocol UpdatingSourceProvider: SourceProvider & AnyUpdatingSourceProvider { - var sourceProviderEventsPublisher: AnyUpdatePublisher> { get } + var sourceProviderEventsPublisher: AnyUpdatePublisher> { + get + } } extension UpdatingSourceProvider { public var typeErasedSourceProviderEventsPublisher: AnyUpdatePublisher { return sourceProviderEventsPublisher.map { event in switch event { - case .startedUpdating: - return .startedUpdating - case .stoppedUpdating(let error): - return .stoppedUpdating(error: error) - case .sourceAdded(let source): - return .sourceAdded(source) - case .sourceRemoved(let source): - return .sourceRemoved(source) + case .startedUpdating: return .startedUpdating + case .stoppedUpdating(let error): return .stoppedUpdating(error: error) + case .sourceAdded(let source): return .sourceAdded(source) + case .sourceRemoved(let source): return .sourceRemoved(source) } }.eraseToAnyUpdatePublisher() } diff --git a/Sources/GatheredKit/Units/UnitFrequency+radiansPerSecond.swift b/Sources/GatheredKit/Units/UnitFrequency+radiansPerSecond.swift index cd917258..fee2cc8b 100644 --- a/Sources/GatheredKit/Units/UnitFrequency+radiansPerSecond.swift +++ b/Sources/GatheredKit/Units/UnitFrequency+radiansPerSecond.swift @@ -4,7 +4,9 @@ extension UnitFrequency { public static var radiansPerSecond: UnitFrequency { return UnitFrequency( - symbol: "rad/s", converter: UnitConverterLinear(coefficient: 2 * Double.pi)) + symbol: "rad/s", + converter: UnitConverterLinear(coefficient: 2 * Double.pi) + ) } } diff --git a/Sources/GatheredKit/Units/UnitMagneticField.swift b/Sources/GatheredKit/Units/UnitMagneticField.swift index 1da78dd7..1418357e 100644 --- a/Sources/GatheredKit/Units/UnitMagneticField.swift +++ b/Sources/GatheredKit/Units/UnitMagneticField.swift @@ -2,14 +2,16 @@ import Foundation public final class UnitMagneticField: Dimension { - public override class func baseUnit() -> UnitMagneticField { - return tesla - } + public override class func baseUnit() -> UnitMagneticField { return tesla } public static let tesla = UnitMagneticField( - symbol: "T", converter: UnitConverterLinear(coefficient: 1)) + symbol: "T", + converter: UnitConverterLinear(coefficient: 1) + ) public static let microTesla = UnitMagneticField( - symbol: "µT", converter: UnitConverterLinear(coefficient: 1 / 1000)) + symbol: "µT", + converter: UnitConverterLinear(coefficient: 1 / 1000) + ) } diff --git a/Sources/GatheredKit/UpdatePublisher/AnyUpdatePublisher.swift b/Sources/GatheredKit/UpdatePublisher/AnyUpdatePublisher.swift index b9d3627b..cea2989d 100644 --- a/Sources/GatheredKit/UpdatePublisher/AnyUpdatePublisher.swift +++ b/Sources/GatheredKit/UpdatePublisher/AnyUpdatePublisher.swift @@ -5,13 +5,12 @@ import Combine public final class AnyUpdatePublisher: UpdatePublisher { public typealias UpdateListener = (_ payload: Payload) -> Void - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - public var combinePublisher: AnyPublisher { - return (boxedCombinePublisher as! BoxedCombinePublisher)() - } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public var combinePublisher: + AnyPublisher + { return (boxedCombinePublisher as! BoxedCombinePublisher)() } - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - private typealias BoxedCombinePublisher = () -> AnyPublisher + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) private typealias + BoxedCombinePublisher = () -> AnyPublisher private let boxedCombinePublisher: Any @@ -21,13 +20,9 @@ public final class AnyUpdatePublisher: UpdatePublisher { where UpdatePublisher.Payload == Payload { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { boxedCombinePublisher = - { - return updatePublisher.combinePublisher - } as BoxedCombinePublisher + { return updatePublisher.combinePublisher } as BoxedCombinePublisher } else { - boxedCombinePublisher = { - fatalError("boxedCombinePublisher unavailable") - } + boxedCombinePublisher = { fatalError("boxedCombinePublisher unavailable") } } boxedAddUpdateListener = { updateListener in diff --git a/Sources/GatheredKit/UpdatePublisher/MappedUpdatePublisher.swift b/Sources/GatheredKit/UpdatePublisher/MappedUpdatePublisher.swift index 29a8c054..bd77d852 100644 --- a/Sources/GatheredKit/UpdatePublisher/MappedUpdatePublisher.swift +++ b/Sources/GatheredKit/UpdatePublisher/MappedUpdatePublisher.swift @@ -11,19 +11,17 @@ public final class MappedUpdatePublisher: UpdatePublisher { #if canImport(Combine) /// A publisher that publishes updates when the snapshot updates. - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - public var combinePublisher: AnyPublisher { - return combineSubject.eraseToAnyPublisher() - } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public var combinePublisher: + AnyPublisher + { return combineSubject.eraseToAnyPublisher() } - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - private typealias PayloadSubject = PassthroughSubject + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) private typealias PayloadSubject = + PassthroughSubject /// The updates subject that publishes snapshot updates. - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - private var combineSubject: PayloadSubject { - return _combineSubject as! PayloadSubject - } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) private var combineSubject: + PayloadSubject + { return _combineSubject as! PayloadSubject } private lazy var _combineSubject: Any = { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { @@ -54,9 +52,7 @@ public final class MappedUpdatePublisher: UpdatePublisher { let uuid = UUID() updateListeners[uuid] = updateListener - return Subscription { [weak self] in - self?.updateListeners.removeValue(forKey: uuid) - } + return Subscription { [weak self] in self?.updateListeners.removeValue(forKey: uuid) } } private func notifyUpdateListeners(of payload: Payload) { diff --git a/Sources/GatheredKit/UpdatePublisher/Subscription.swift b/Sources/GatheredKit/UpdatePublisher/Subscription.swift index 05c4c380..acd1cae6 100644 --- a/Sources/GatheredKit/UpdatePublisher/Subscription.swift +++ b/Sources/GatheredKit/UpdatePublisher/Subscription.swift @@ -8,9 +8,7 @@ public final class Subscription { self.cancelHandler = cancelHandler } - deinit { - cancel() - } + deinit { cancel() } public func cancel() { guard let cancelHandler = cancelHandler else { return } diff --git a/Sources/GatheredKit/UpdatePublisher/UpdatePublisher.swift b/Sources/GatheredKit/UpdatePublisher/UpdatePublisher.swift index 394adbd0..3ef92600 100644 --- a/Sources/GatheredKit/UpdatePublisher/UpdatePublisher.swift +++ b/Sources/GatheredKit/UpdatePublisher/UpdatePublisher.swift @@ -8,8 +8,9 @@ public protocol UpdatePublisher { typealias UpdateListener = (_ payload: Payload) -> Void #if canImport(Combine) - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - var combinePublisher: AnyPublisher { get } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) var combinePublisher: + AnyPublisher + { get } #endif func addUpdateListener(_ updateListener: @escaping UpdateListener) -> Subscription @@ -22,7 +23,5 @@ extension UpdatePublisher { public func map(_ transform: @escaping (_ payload: Payload) -> Output) -> MappedUpdatePublisher - { - return MappedUpdatePublisher(updatePublisher: self, transform: transform) - } + { return MappedUpdatePublisher(updatePublisher: self, transform: transform) } } diff --git a/Sources/GatheredKit/UpdatePublisher/UpdateSubject.swift b/Sources/GatheredKit/UpdatePublisher/UpdateSubject.swift index d85757fe..809ab586 100644 --- a/Sources/GatheredKit/UpdatePublisher/UpdateSubject.swift +++ b/Sources/GatheredKit/UpdatePublisher/UpdateSubject.swift @@ -11,19 +11,17 @@ open class UpdateSubject: UpdatePublisher { #if canImport(Combine) /// A publisher that publishes updates when the snapshot updates. - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - public var combinePublisher: AnyPublisher { - return combineSubject.eraseToAnyPublisher() - } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public var combinePublisher: + AnyPublisher + { return combineSubject.eraseToAnyPublisher() } - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - private typealias PayloadSubject = PassthroughSubject + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) private typealias PayloadSubject = + PassthroughSubject /// The updates subject that publishes snapshot updates. - @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - private var combineSubject: PayloadSubject { - return _combineSubject as! PayloadSubject - } + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) private var combineSubject: + PayloadSubject + { return _combineSubject as! PayloadSubject } private lazy var _combineSubject: Any = { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { @@ -36,10 +34,9 @@ open class UpdateSubject: UpdatePublisher { public init() {} - @available(*, deprecated, renamed: "notifyUpdateListeners(of:)") - public func send(_ payload: Payload) { - notifyUpdateListeners(of: payload) - } + @available(*, deprecated, renamed: "notifyUpdateListeners(of:)") public func send( + _ payload: Payload + ) { notifyUpdateListeners(of: payload) } open func notifyUpdateListeners(of payload: Payload) { updateListeners.lazy.map(\.value).forEach { $0(payload) } @@ -56,8 +53,6 @@ open class UpdateSubject: UpdatePublisher { let uuid = UUID() updateListeners[uuid] = updateListener - return Subscription { [weak self] in - self?.updateListeners.removeValue(forKey: uuid) - } + return Subscription { [weak self] in self?.updateListeners.removeValue(forKey: uuid) } } } diff --git a/Sources/GatheredKitLocation/Formatters/CoordinateFormatter.swift b/Sources/GatheredKitLocation/Formatters/CoordinateFormatter.swift index bb412775..63262c6d 100644 --- a/Sources/GatheredKitLocation/Formatters/CoordinateFormatter.swift +++ b/Sources/GatheredKitLocation/Formatters/CoordinateFormatter.swift @@ -35,14 +35,12 @@ public final class CoordinateFormatter: Formatter { } public override func string(for obj: Any?) -> String? { - guard - let coordinate = obj as? CLLocationCoordinate2D, + guard let coordinate = obj as? CLLocationCoordinate2D, let latitudeString = numberFormatter.string(from: NSNumber(value: coordinate.latitude)), let longitudeString = numberFormatter.string( - from: NSNumber(value: coordinate.longitude)) - else { - return nil - } + from: NSNumber(value: coordinate.longitude) + ) + else { return nil } return latitudeString + ", " + longitudeString } diff --git a/Sources/GatheredKitLocation/Formatters/LocationAuthorizationFormatter.swift b/Sources/GatheredKitLocation/Formatters/LocationAuthorizationFormatter.swift index 9cf2bd88..f8f0dbd2 100644 --- a/Sources/GatheredKitLocation/Formatters/LocationAuthorizationFormatter.swift +++ b/Sources/GatheredKitLocation/Formatters/LocationAuthorizationFormatter.swift @@ -5,18 +5,12 @@ public final class LocationAuthorizationFormatter: Formatter { public func string(for status: CLAuthorizationStatus) -> String { switch status { - case .authorizedAlways: - return "Always" - case .authorizedWhenInUse: - return "When In Use" - case .denied: - return "Denied" - case .notDetermined: - return "Not Determined" - case .restricted: - return "Restricted" - @unknown default: - return "Unknown" + case .authorizedAlways: return "Always" + case .authorizedWhenInUse: return "When In Use" + case .denied: return "Denied" + case .notDetermined: return "Not Determined" + case .restricted: return "Restricted" + @unknown default: return "Unknown" } } diff --git a/Sources/GatheredKitLocation/Properties/CoordinateProperty.swift b/Sources/GatheredKitLocation/Properties/CoordinateProperty.swift index de7bd7af..85e3c52a 100644 --- a/Sources/GatheredKitLocation/Properties/CoordinateProperty.swift +++ b/Sources/GatheredKitLocation/Properties/CoordinateProperty.swift @@ -2,37 +2,23 @@ import CoreLocation import Foundation import GatheredKit -@propertyWrapper -public final class CoordinateProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CoordinateProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CLLocationCoordinate2D - public var allProperties: [AnyProperty] { - return [ - $latitude, - $longitude, - ] - } + public var allProperties: [AnyProperty] { return [$latitude, $longitude] } public var wrappedValue: CLLocationCoordinate2D { - get { - return snapshot.value - } - set { - updateValue(newValue) - } + get { return snapshot.value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A human-friendly display name that describes the property. @@ -50,15 +36,15 @@ public final class CoordinateProperty: UpdatableProperty, PropertiesProvider { // MARK: Coodinate Properties - @AngleProperty - public private(set) var latitude: Measurement + @AngleProperty public private(set) var latitude: Measurement - @AngleProperty - public private(set) var longitude: Measurement + @AngleProperty public private(set) var longitude: Measurement public required init( - displayName: String, value: CLLocationCoordinate2D, - formatter: CoordinateFormatter = CoordinateFormatter(), date: Date = Date() + displayName: String, + value: CLLocationCoordinate2D, + formatter: CoordinateFormatter = CoordinateFormatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -68,7 +54,9 @@ public final class CoordinateProperty: UpdatableProperty, PropertiesProvider { _longitude = .degrees(displayName: "Longitude", value: value.longitude, date: date) } - public func updateValue(_ value: CLLocationCoordinate2D, date: Date) -> Snapshot { + public func updateValue(_ value: CLLocationCoordinate2D, date: Date) -> Snapshot< + CLLocationCoordinate2D + > { _latitude.updateMeasuredValue(value.latitude, date: date) _longitude.updateMeasuredValue(value.longitude, date: date) diff --git a/Sources/GatheredKitLocation/Properties/OptionalCoordinateProperty.swift b/Sources/GatheredKitLocation/Properties/OptionalCoordinateProperty.swift index cdeb87db..de0327a1 100644 --- a/Sources/GatheredKitLocation/Properties/OptionalCoordinateProperty.swift +++ b/Sources/GatheredKitLocation/Properties/OptionalCoordinateProperty.swift @@ -6,33 +6,20 @@ import GatheredKit public final class OptionalCoordinateProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CLLocationCoordinate2D? - public var allProperties: [AnyProperty] { - return [ - $latitude, - $longitude, - ] - } + public var allProperties: [AnyProperty] { return [$latitude, $longitude] } public var wrappedValue: CLLocationCoordinate2D? { - get { - return snapshot.value - } - set { - updateValue(newValue) - } + get { return snapshot.value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A human-friendly display name that describes the property. @@ -50,15 +37,15 @@ public final class OptionalCoordinateProperty: UpdatableProperty, PropertiesProv // MARK: Coodinate Properties - @OptionalAngleProperty - public private(set) var latitude: Measurement? + @OptionalAngleProperty public private(set) var latitude: Measurement? - @OptionalAngleProperty - public private(set) var longitude: Measurement? + @OptionalAngleProperty public private(set) var longitude: Measurement? public required init( - displayName: String, value: CLLocationCoordinate2D? = nil, - formatter: CoordinateFormatter = CoordinateFormatter(), date: Date = Date() + displayName: String, + value: CLLocationCoordinate2D? = nil, + formatter: CoordinateFormatter = CoordinateFormatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -68,7 +55,9 @@ public final class OptionalCoordinateProperty: UpdatableProperty, PropertiesProv _longitude = .degrees(displayName: "Longitude", value: value?.longitude, date: date) } - public func updateValue(_ value: CLLocationCoordinate2D?, date: Date) -> Snapshot { + public func updateValue(_ value: CLLocationCoordinate2D?, date: Date) -> Snapshot< + CLLocationCoordinate2D? + > { _latitude.updateMeasuredValue(value?.latitude, date: date) _longitude.updateMeasuredValue(value?.longitude, date: date) diff --git a/Sources/GatheredKitLocation/Sources/Location.swift b/Sources/GatheredKitLocation/Sources/Location.swift index defebfec..bba9ed46 100644 --- a/Sources/GatheredKitLocation/Sources/Location.swift +++ b/Sources/GatheredKitLocation/Sources/Location.swift @@ -22,29 +22,22 @@ public final class Location: NSObject, UpdatingSource, Controllable { private let sourceEventsSubject: UpdateSubject - @OptionalCoordinateProperty - public private(set) var coordinate: CLLocationCoordinate2D? + @OptionalCoordinateProperty public private(set) var coordinate: CLLocationCoordinate2D? - @OptionalSpeedProperty - public private(set) var speed: Measurement? + @OptionalSpeedProperty public private(set) var speed: Measurement? - @OptionalAngleProperty - public private(set) var course: Measurement? + @OptionalAngleProperty public private(set) var course: Measurement? - @OptionalLengthProperty - public private(set) var altitude: Measurement? + @OptionalLengthProperty public private(set) var altitude: Measurement? - @OptionalIntProperty - public private(set) var floor: Int? + @OptionalIntProperty public private(set) var floor: Int? - @OptionalLengthProperty - public private(set) var horizonalAccuracy: Measurement? + @OptionalLengthProperty public private(set) var horizonalAccuracy: Measurement? - @OptionalLengthProperty - public private(set) var verticalAccuracy: Measurement? + @OptionalLengthProperty public private(set) var verticalAccuracy: Measurement? - @CLLocationAuthorizationProperty - public private(set) var authorizationStatus: CLAuthorizationStatus + @CLLocationAuthorizationProperty public private(set) var authorizationStatus: + CLAuthorizationStatus /** An array of all the properties associated with the location of the @@ -60,13 +53,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { */ public var allProperties: [AnyProperty] { return [ - $coordinate, - $speed, - $course, - $altitude, - $floor, - $horizonalAccuracy, - $verticalAccuracy, + $coordinate, $speed, $course, $altitude, $floor, $horizonalAccuracy, $verticalAccuracy, $authorizationStatus, ] } @@ -82,11 +69,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { } private var isAskingForLocationPermissions: Bool { - if case .askingForPermissions = state { - return true - } else { - return false - } + if case .askingForPermissions = state { return true } else { return false } } private var state: State = .notMonitoring { @@ -117,16 +100,16 @@ public final class Location: NSObject, UpdatingSource, Controllable { _horizonalAccuracy = .meters(displayName: "Horizontal Accuracy") _verticalAccuracy = .meters(displayName: "Vertical Accuracy") _authorizationStatus = .init( - displayName: "Authorization Status", value: CLLocationManager.authorizationStatus()) + displayName: "Authorization Status", + value: CLLocationManager.authorizationStatus() + ) sourceEventsSubject = UpdateSubject() super.init() } - deinit { - stopUpdating() - } + deinit { stopUpdating() } #if os(iOS) || os(watchOS) public func startUpdating() { @@ -134,16 +117,15 @@ public final class Location: NSObject, UpdatingSource, Controllable { } public func startUpdating( - allowBackgroundUpdates: Bool = false, desiredAccuracy accuracy: Accuracy = .best + allowBackgroundUpdates: Bool = false, + desiredAccuracy accuracy: Accuracy = .best ) { startUpdating(desiredAccuracy: accuracy) { locationManager in locationManager.allowsBackgroundLocationUpdates = allowBackgroundUpdates } } #elseif os(macOS) || os(tvOS) - public func startUpdating() { - startUpdating(desiredAccuracy: .best) - } + public func startUpdating() { startUpdating(desiredAccuracy: .best) } public func startUpdating(desiredAccuracy accuracy: Accuracy = .best) { startUpdating(desiredAccuracy: accuracy, locationManagerConfigurator: nil) @@ -196,8 +178,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { case .denied, .restricted: updateLocationValues(nil) state = .notMonitoring - @unknown default: - break + @unknown default: break } #elseif os(macOS) switch authorizationStatus { @@ -215,8 +196,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { case .denied, .restricted: updateLocationValues(nil) state = .notMonitoring - @unknown default: - break + @unknown default: break } #elseif os(tvOS) switch authorizationStatus { @@ -230,8 +210,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { case .denied, .restricted: updateLocationValues(nil) state = .notMonitoring - @unknown default: - break + @unknown default: break } #endif } @@ -243,9 +222,7 @@ public final class Location: NSObject, UpdatingSource, Controllable { state = .notMonitoring } - private func updateValues() { - updateLocationValues(locationManager?.location) - } + private func updateValues() { updateLocationValues(locationManager?.location) } private func updateLocationValues(_ location: CLLocation? = nil) { let coordinateSnapshot: Snapshot @@ -257,13 +234,33 @@ public final class Location: NSObject, UpdatingSource, Controllable { let verticalAccuracySnapshot: Snapshot?> defer { - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $coordinate, snapshot: coordinateSnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $speed, snapshot: speedSnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $course, snapshot: courseSnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $altitude, snapshot: altitudeSnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $floor, snapshot: floorSnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $horizonalAccuracy, snapshot: horizonalAccuracySnapshot)) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $verticalAccuracy, snapshot: verticalAccuracySnapshot)) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $coordinate, snapshot: coordinateSnapshot) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $speed, snapshot: speedSnapshot) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $course, snapshot: courseSnapshot) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $altitude, snapshot: altitudeSnapshot) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $floor, snapshot: floorSnapshot) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated( + property: $horizonalAccuracy, + snapshot: horizonalAccuracySnapshot + ) + ) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated( + property: $verticalAccuracy, + snapshot: verticalAccuracySnapshot + ) + ) } if let location = location { @@ -287,8 +284,14 @@ public final class Location: NSObject, UpdatingSource, Controllable { altitudeSnapshot = _altitude.updateMeasuredValue(location.altitude, date: timestamp) floorSnapshot = _floor.updateValue(location.floor?.level, date: timestamp) - horizonalAccuracySnapshot = _horizonalAccuracy.updateMeasuredValue(location.horizontalAccuracy, date: timestamp) - verticalAccuracySnapshot = _verticalAccuracy.updateMeasuredValue(location.verticalAccuracy, date: timestamp) + horizonalAccuracySnapshot = _horizonalAccuracy.updateMeasuredValue( + location.horizontalAccuracy, + date: timestamp + ) + verticalAccuracySnapshot = _verticalAccuracy.updateMeasuredValue( + location.verticalAccuracy, + date: timestamp + ) } else { coordinateSnapshot = _coordinate.updateValue(nil) speedSnapshot = _speed.updateValue(nil) @@ -305,13 +308,16 @@ public final class Location: NSObject, UpdatingSource, Controllable { extension Location: CLLocationManagerDelegate { public func locationManager( - _ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus + _ manager: CLLocationManager, + didChangeAuthorization status: CLAuthorizationStatus ) { availability = SourceAvailability(authorizationStatus: status) ?? .unavailable sourceEventsSubject.notifyUpdateListeners(of: .availabilityUpdated(availability)) let snapshot = _authorizationStatus.updateValue(status) - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $authorizationStatus, snapshot: snapshot)) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $authorizationStatus, snapshot: snapshot) + ) switch availability { case .available: @@ -333,10 +339,9 @@ extension Location: CLLocationManagerDelegate { } public func locationManager( - _ manager: CLLocationManager, didUpdateLocations locations: [CLLocation] - ) { - locations.forEach(updateLocationValues(_:)) - } + _ manager: CLLocationManager, + didUpdateLocations locations: [CLLocation] + ) { locations.forEach(updateLocationValues(_:)) } } @@ -352,37 +357,24 @@ extension Location { public var asCLLocationAccuracy: CLLocationAccuracy { switch self { - case .bestForNavigation: - return kCLLocationAccuracyBestForNavigation - case .best: - return kCLLocationAccuracyBest - case .tenMeters: - return kCLLocationAccuracyNearestTenMeters - case .hundredMeters: - return kCLLocationAccuracyHundredMeters - case .kilometer: - return kCLLocationAccuracyKilometer - case .threeKilometers: - return kCLLocationAccuracyThreeKilometers + case .bestForNavigation: return kCLLocationAccuracyBestForNavigation + case .best: return kCLLocationAccuracyBest + case .tenMeters: return kCLLocationAccuracyNearestTenMeters + case .hundredMeters: return kCLLocationAccuracyHundredMeters + case .kilometer: return kCLLocationAccuracyKilometer + case .threeKilometers: return kCLLocationAccuracyThreeKilometers } } public init?(accuracy: CLLocationAccuracy) { switch accuracy { - case kCLLocationAccuracyBestForNavigation: - self = .bestForNavigation - case kCLLocationAccuracyBest: - self = .best - case kCLLocationAccuracyNearestTenMeters: - self = .tenMeters - case kCLLocationAccuracyHundredMeters: - self = .hundredMeters - case kCLLocationAccuracyKilometer: - self = .kilometer - case kCLLocationAccuracyThreeKilometers: - self = .threeKilometers - default: - return nil + case kCLLocationAccuracyBestForNavigation: self = .bestForNavigation + case kCLLocationAccuracyBest: self = .best + case kCLLocationAccuracyNearestTenMeters: self = .tenMeters + case kCLLocationAccuracyHundredMeters: self = .hundredMeters + case kCLLocationAccuracyKilometer: self = .kilometer + case kCLLocationAccuracyThreeKilometers: self = .threeKilometers + default: return nil } } @@ -395,29 +387,19 @@ extension SourceAvailability { public init?(authorizationStatus: CLAuthorizationStatus) { #if os(iOS) || os(tvOS) || os(watchOS) switch authorizationStatus { - case .authorizedAlways, .authorizedWhenInUse: - self = .available - case .denied: - self = .permissionDenied - case .restricted: - self = .restricted - case .notDetermined: - self = .requiresPermissionsPrompt - @unknown default: - return nil + case .authorizedAlways, .authorizedWhenInUse: self = .available + case .denied: self = .permissionDenied + case .restricted: self = .restricted + case .notDetermined: self = .requiresPermissionsPrompt + @unknown default: return nil } #elseif os(macOS) switch authorizationStatus { - case .authorizedAlways: - self = .available - case .denied: - self = .permissionDenied - case .restricted: - self = .restricted - case .notDetermined: - self = .requiresPermissionsPrompt - @unknown default: - return nil + case .authorizedAlways: self = .available + case .denied: self = .permissionDenied + case .restricted: self = .restricted + case .notDetermined: self = .requiresPermissionsPrompt + @unknown default: return nil } #endif } diff --git a/Sources/GatheredKitMotion/Formatters/MagneticFieldCalibrationAccuracyFormatter.swift b/Sources/GatheredKitMotion/Formatters/MagneticFieldCalibrationAccuracyFormatter.swift index c49fada8..c98f55b0 100644 --- a/Sources/GatheredKitMotion/Formatters/MagneticFieldCalibrationAccuracyFormatter.swift +++ b/Sources/GatheredKitMotion/Formatters/MagneticFieldCalibrationAccuracyFormatter.swift @@ -6,16 +6,11 @@ public final class MagneticFieldCalibrationAccuracyFormatter: Formatter { public func string(for status: CMMagneticFieldCalibrationAccuracy) -> String { switch status { - case .uncalibrated: - return "Uncalibrated" - case .low: - return "Low" - case .medium: - return "Medium" - case .high: - return "High" - @unknown default: - return "Unknown" + case .uncalibrated: return "Uncalibrated" + case .low: return "Low" + case .medium: return "Medium" + case .high: return "High" + @unknown default: return "Unknown" } } diff --git a/Sources/GatheredKitMotion/Properties/CMAccelerationProperty.swift b/Sources/GatheredKitMotion/Properties/CMAccelerationProperty.swift index 96c66c13..4e8ee417 100644 --- a/Sources/GatheredKitMotion/Properties/CMAccelerationProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMAccelerationProperty.swift @@ -3,38 +3,26 @@ import Foundation import CoreMotion import GatheredKit -@propertyWrapper -public final class CMAccelerationProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CMAccelerationProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CMAcceleration public typealias Formatter = CMAccelerationFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @AccelerationProperty - public private(set) var x: Measurement + @AccelerationProperty public private(set) var x: Measurement - @AccelerationProperty - public private(set) var y: Measurement + @AccelerationProperty public private(set) var y: Measurement - @AccelerationProperty - public private(set) var z: Measurement + @AccelerationProperty public private(set) var z: Measurement // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -43,9 +31,7 @@ public final class CMAccelerationProperty: UpdatableProperty, PropertiesProvider /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +47,10 @@ public final class CMAccelerationProperty: UpdatableProperty, PropertiesProvider // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -73,8 +62,7 @@ public final class CMAccelerationProperty: UpdatableProperty, PropertiesProvider _z = .gravity(displayName: "z", value: value.z, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateMeasuredValue(value.x, date: date) _y.updateMeasuredValue(value.y, date: date) _z.updateMeasuredValue(value.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/CMAttitudeProperty.swift b/Sources/GatheredKitMotion/Properties/CMAttitudeProperty.swift index 23ca6d0f..b76221e7 100644 --- a/Sources/GatheredKitMotion/Properties/CMAttitudeProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMAttitudeProperty.swift @@ -5,43 +5,30 @@ import GatheredKit // TODO: Add rotationMatrix -@propertyWrapper -public final class CMAttitudeProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CMAttitudeProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CMAttitude public typealias Formatter = CMAttitudeFormatter // MARK: `CMAttitude` Properties - public var allProperties: [AnyProperty] { - return [$roll, $pitch, $yaw, $quaternion] - } + public var allProperties: [AnyProperty] { return [$roll, $pitch, $yaw, $quaternion] } - @AngleProperty - public private(set) var roll: Measurement + @AngleProperty public private(set) var roll: Measurement - @AngleProperty - public private(set) var pitch: Measurement + @AngleProperty public private(set) var pitch: Measurement - @AngleProperty - public private(set) var yaw: Measurement + @AngleProperty public private(set) var yaw: Measurement - @CMQuaternionProperty - public private(set) var quaternion: CMQuaternion + @CMQuaternionProperty public private(set) var quaternion: CMQuaternion // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -50,9 +37,7 @@ public final class CMAttitudeProperty: UpdatableProperty, PropertiesProvider { /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -68,8 +53,10 @@ public final class CMAttitudeProperty: UpdatableProperty, PropertiesProvider { // MARK: Initialisers public init( - displayName: String, value: CMAttitude, - formatter: CMAttitudeFormatter = CMAttitudeFormatter(), date: Date = Date() + displayName: String, + value: CMAttitude, + formatter: CMAttitudeFormatter = CMAttitudeFormatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -84,8 +71,7 @@ public final class CMAttitudeProperty: UpdatableProperty, PropertiesProvider { // MARK: Update Functions - @discardableResult - public func updateValue(_ value: CMAttitude, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: CMAttitude, date: Date) -> Snapshot { _roll.updateMeasuredValue(value.roll, date: date) _pitch.updateMeasuredValue(value.pitch, date: date) _yaw.updateMeasuredValue(value.yaw, date: date) diff --git a/Sources/GatheredKitMotion/Properties/CMCalibratedMagneticFieldProperty.swift b/Sources/GatheredKitMotion/Properties/CMCalibratedMagneticFieldProperty.swift index 42879181..2492c1e0 100644 --- a/Sources/GatheredKitMotion/Properties/CMCalibratedMagneticFieldProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMCalibratedMagneticFieldProperty.swift @@ -9,25 +9,18 @@ public final class CMCalibratedMagneticFieldProperty: UpdatableProperty, Propert // TODO: Create `CMCalibratedMagneticFieldFormatter` public typealias Formatter = CMMagneticFieldFormatter - public var allProperties: [AnyProperty] { - return [$accuracy, $field] - } + public var allProperties: [AnyProperty] { return [$accuracy, $field] } - @CMMagneticFieldCalibrationAccuracyProperty - public private(set) var accuracy: CMMagneticFieldCalibrationAccuracy + @CMMagneticFieldCalibrationAccuracyProperty public private(set) var accuracy: + CMMagneticFieldCalibrationAccuracy - @CMMagneticFieldProperty - public private(set) var field: CMMagneticField + @CMMagneticFieldProperty public private(set) var field: CMMagneticField // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty { @@ -41,9 +34,7 @@ public final class CMCalibratedMagneticFieldProperty: UpdatableProperty, Propert /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -59,7 +50,10 @@ public final class CMCalibratedMagneticFieldProperty: UpdatableProperty, Propert // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -70,8 +64,7 @@ public final class CMCalibratedMagneticFieldProperty: UpdatableProperty, Propert _field = .init(displayName: "Field", value: value.field, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _accuracy.updateValue(value.accuracy, date: date) _field.updateValue(value.field, date: date) diff --git a/Sources/GatheredKitMotion/Properties/CMMagneticFieldProperty.swift b/Sources/GatheredKitMotion/Properties/CMMagneticFieldProperty.swift index 54e9e073..00860547 100644 --- a/Sources/GatheredKitMotion/Properties/CMMagneticFieldProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMMagneticFieldProperty.swift @@ -3,38 +3,26 @@ import Foundation import CoreMotion import GatheredKit -@propertyWrapper -public final class CMMagneticFieldProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CMMagneticFieldProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CMMagneticField public typealias Formatter = CMMagneticFieldFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @MagneticFieldProperty - public private(set) var x: Measurement + @MagneticFieldProperty public private(set) var x: Measurement - @MagneticFieldProperty - public private(set) var y: Measurement + @MagneticFieldProperty public private(set) var y: Measurement - @MagneticFieldProperty - public private(set) var z: Measurement + @MagneticFieldProperty public private(set) var z: Measurement // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -43,9 +31,7 @@ public final class CMMagneticFieldProperty: UpdatableProperty, PropertiesProvide /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +47,10 @@ public final class CMMagneticFieldProperty: UpdatableProperty, PropertiesProvide // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -73,8 +62,7 @@ public final class CMMagneticFieldProperty: UpdatableProperty, PropertiesProvide _z = .microTesla(displayName: "z", value: value.z, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateMeasuredValue(value.x, date: date) _y.updateMeasuredValue(value.y, date: date) _z.updateMeasuredValue(value.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/CMQuaternionProperty.swift b/Sources/GatheredKitMotion/Properties/CMQuaternionProperty.swift index 85e68964..d805b492 100644 --- a/Sources/GatheredKitMotion/Properties/CMQuaternionProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMQuaternionProperty.swift @@ -3,46 +3,28 @@ import Foundation import CoreMotion import GatheredKit -@propertyWrapper -public final class CMQuaternionProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CMQuaternionProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CMQuaternion public typealias Formatter = CMQuaternionFormatter - public var allProperties: [AnyProperty] { - return [ - $x, - $y, - $z, - $w, - ] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z, $w] } - @DoubleProperty - public private(set) var x: Double + @DoubleProperty public private(set) var x: Double - @DoubleProperty - public private(set) var y: Double + @DoubleProperty public private(set) var y: Double - @DoubleProperty - public private(set) var z: Double + @DoubleProperty public private(set) var z: Double - @DoubleProperty - public private(set) var w: Double + @DoubleProperty public private(set) var w: Double // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -51,9 +33,7 @@ public final class CMQuaternionProperty: UpdatableProperty, PropertiesProvider { /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -69,7 +49,10 @@ public final class CMQuaternionProperty: UpdatableProperty, PropertiesProvider { // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -84,8 +67,7 @@ public final class CMQuaternionProperty: UpdatableProperty, PropertiesProvider { // MARK: Update Functions - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateValue(value.x, date: date) _y.updateValue(value.y, date: date) _z.updateValue(value.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/CMRotationRateProperty.swift b/Sources/GatheredKitMotion/Properties/CMRotationRateProperty.swift index 0d640101..22310cb0 100644 --- a/Sources/GatheredKitMotion/Properties/CMRotationRateProperty.swift +++ b/Sources/GatheredKitMotion/Properties/CMRotationRateProperty.swift @@ -3,38 +3,26 @@ import Foundation import CoreMotion import GatheredKit -@propertyWrapper -public final class CMRotationRateProperty: UpdatableProperty, PropertiesProvider { +@propertyWrapper public final class CMRotationRateProperty: UpdatableProperty, PropertiesProvider { public typealias Value = CMRotationRate public typealias Formatter = CMRotationRateFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @FrequencyProperty - public private(set) var x: Measurement + @FrequencyProperty public private(set) var x: Measurement - @FrequencyProperty - public private(set) var y: Measurement + @FrequencyProperty public private(set) var y: Measurement - @FrequencyProperty - public private(set) var z: Measurement + @FrequencyProperty public private(set) var z: Measurement // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -43,9 +31,7 @@ public final class CMRotationRateProperty: UpdatableProperty, PropertiesProvider /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +47,10 @@ public final class CMRotationRateProperty: UpdatableProperty, PropertiesProvider // MARK: Initialisers public required init( - displayName: String, value: Value, formatter: Formatter = Formatter(), date: Date = Date() + displayName: String, + value: Value, + formatter: Formatter = Formatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMAccelerationProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMAccelerationProperty.swift index 8847ff56..6cff89b4 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMAccelerationProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMAccelerationProperty.swift @@ -8,28 +8,19 @@ public final class OptionalCMAccelerationProperty: UpdatableProperty, Properties public typealias Value = CMAcceleration? public typealias Formatter = CMAccelerationFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @OptionalAccelerationProperty - public private(set) var x: Measurement? + @OptionalAccelerationProperty public private(set) var x: Measurement? - @OptionalAccelerationProperty - public private(set) var y: Measurement? + @OptionalAccelerationProperty public private(set) var y: Measurement? - @OptionalAccelerationProperty - public private(set) var z: Measurement? + @OptionalAccelerationProperty public private(set) var z: Measurement? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty { @@ -43,9 +34,7 @@ public final class OptionalCMAccelerationProperty: UpdatableProperty, Properties /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +50,9 @@ public final class OptionalCMAccelerationProperty: UpdatableProperty, Properties // MARK: Initialisers public required init( - displayName: String, value: Value = nil, formatter: Formatter = Formatter(), + displayName: String, + value: Value = nil, + formatter: Formatter = Formatter(), date: Date = Date() ) { self.displayName = displayName @@ -74,8 +65,7 @@ public final class OptionalCMAccelerationProperty: UpdatableProperty, Properties _z = .gravity(displayName: "z", value: value?.z, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateMeasuredValue(value?.x, date: date) _y.updateMeasuredValue(value?.y, date: date) _z.updateMeasuredValue(value?.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMAttitudeProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMAttitudeProperty.swift index 149eb7a4..ee0f279f 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMAttitudeProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMAttitudeProperty.swift @@ -12,36 +12,24 @@ public final class OptionalCMAttitudeProperty: UpdatableProperty, PropertiesProv // MARK: `CMAttitude` Properties - public var allProperties: [AnyProperty] { - return [$roll, $pitch, $yaw, $quaternion] - } + public var allProperties: [AnyProperty] { return [$roll, $pitch, $yaw, $quaternion] } - @OptionalAngleProperty - public private(set) var roll: Measurement? + @OptionalAngleProperty public private(set) var roll: Measurement? - @OptionalAngleProperty - public private(set) var pitch: Measurement? + @OptionalAngleProperty public private(set) var pitch: Measurement? - @OptionalAngleProperty - public private(set) var yaw: Measurement? + @OptionalAngleProperty public private(set) var yaw: Measurement? - @OptionalCMQuaternionProperty - public private(set) var quaternion: CMQuaternion? + @OptionalCMQuaternionProperty public private(set) var quaternion: CMQuaternion? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -50,9 +38,7 @@ public final class OptionalCMAttitudeProperty: UpdatableProperty, PropertiesProv /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -68,8 +54,10 @@ public final class OptionalCMAttitudeProperty: UpdatableProperty, PropertiesProv // MARK: Initialisers public init( - displayName: String, value: Value = nil, - formatter: CMAttitudeFormatter = CMAttitudeFormatter(), date: Date = Date() + displayName: String, + value: Value = nil, + formatter: CMAttitudeFormatter = CMAttitudeFormatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -84,8 +72,9 @@ public final class OptionalCMAttitudeProperty: UpdatableProperty, PropertiesProv // MARK: Update Functions - @discardableResult - public func updateValue(_ value: Value, date: Date = Date()) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date = Date()) -> Snapshot< + Value + > { _roll.updateMeasuredValue(value?.roll, date: date) _pitch.updateMeasuredValue(value?.pitch, date: date) _yaw.updateMeasuredValue(value?.yaw, date: date) diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMCalibratedMagneticFieldProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMCalibratedMagneticFieldProperty.swift index 3f55dc1e..73000911 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMCalibratedMagneticFieldProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMCalibratedMagneticFieldProperty.swift @@ -4,30 +4,24 @@ import CoreMotion import GatheredKit @propertyWrapper -public final class OptionalCMCalibratedMagneticFieldProperty: UpdatableProperty, PropertiesProvider { +public final class OptionalCMCalibratedMagneticFieldProperty: UpdatableProperty, PropertiesProvider +{ public typealias Value = CMCalibratedMagneticField? // TODO: Create `CMCalibratedMagneticFieldFormatter` public typealias Formatter = CMMagneticFieldFormatter - public var allProperties: [AnyProperty] { - return [$accuracy, $field] - } + public var allProperties: [AnyProperty] { return [$accuracy, $field] } - @OptionalCMMagneticFieldCalibrationAccuracyProperty - public private(set) var accuracy: CMMagneticFieldCalibrationAccuracy? + @OptionalCMMagneticFieldCalibrationAccuracyProperty public private(set) var accuracy: + CMMagneticFieldCalibrationAccuracy? - @OptionalCMMagneticFieldProperty - public private(set) var field: CMMagneticField? + @OptionalCMMagneticFieldProperty public private(set) var field: CMMagneticField? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty { @@ -41,9 +35,7 @@ public final class OptionalCMCalibratedMagneticFieldProperty: UpdatableProperty, /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -59,7 +51,9 @@ public final class OptionalCMCalibratedMagneticFieldProperty: UpdatableProperty, // MARK: Initialisers public required init( - displayName: String, value: Value = nil, formatter: Formatter = Formatter(), + displayName: String, + value: Value = nil, + formatter: Formatter = Formatter(), date: Date = Date() ) { self.displayName = displayName @@ -71,8 +65,7 @@ public final class OptionalCMCalibratedMagneticFieldProperty: UpdatableProperty, _field = .init(displayName: "Field", value: value?.field, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _accuracy.updateValue(value?.accuracy, date: date) _field.updateValue(value?.field, date: date) diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMMagneticFieldProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMMagneticFieldProperty.swift index 8f4aa094..0000a96d 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMMagneticFieldProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMMagneticFieldProperty.swift @@ -8,28 +8,19 @@ public final class OptionalCMMagneticFieldProperty: UpdatableProperty, Propertie public typealias Value = CMMagneticField? public typealias Formatter = CMMagneticFieldFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @OptionalMagneticFieldProperty - public private(set) var x: Measurement? + @OptionalMagneticFieldProperty public private(set) var x: Measurement? - @OptionalMagneticFieldProperty - public private(set) var y: Measurement? + @OptionalMagneticFieldProperty public private(set) var y: Measurement? - @OptionalMagneticFieldProperty - public private(set) var z: Measurement? + @OptionalMagneticFieldProperty public private(set) var z: Measurement? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty { @@ -43,9 +34,7 @@ public final class OptionalCMMagneticFieldProperty: UpdatableProperty, Propertie /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +50,9 @@ public final class OptionalCMMagneticFieldProperty: UpdatableProperty, Propertie // MARK: Initialisers public required init( - displayName: String, value: Value = nil, formatter: Formatter = Formatter(), + displayName: String, + value: Value = nil, + formatter: Formatter = Formatter(), date: Date = Date() ) { self.displayName = displayName @@ -74,8 +65,7 @@ public final class OptionalCMMagneticFieldProperty: UpdatableProperty, Propertie _z = .microTesla(displayName: "z", value: value?.z, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateMeasuredValue(value?.x, date: date) _y.updateMeasuredValue(value?.y, date: date) _z.updateMeasuredValue(value?.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMQuaternionProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMQuaternionProperty.swift index 1afe7327..cf537da2 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMQuaternionProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMQuaternionProperty.swift @@ -8,41 +8,24 @@ public final class OptionalCMQuaternionProperty: UpdatableProperty, PropertiesPr public typealias Value = CMQuaternion? public typealias Formatter = CMQuaternionFormatter - public var allProperties: [AnyProperty] { - return [ - $x, - $y, - $z, - $w, - ] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z, $w] } - @OptionalDoubleProperty - public private(set) var x: Double? + @OptionalDoubleProperty public private(set) var x: Double? - @OptionalDoubleProperty - public private(set) var y: Double? + @OptionalDoubleProperty public private(set) var y: Double? - @OptionalDoubleProperty - public private(set) var z: Double? + @OptionalDoubleProperty public private(set) var z: Double? - @OptionalDoubleProperty - public private(set) var w: Double? + @OptionalDoubleProperty public private(set) var w: Double? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } - public var projectedValue: ReadOnlyProperty { - asReadOnlyProperty - } + public var projectedValue: ReadOnlyProperty { asReadOnlyProperty } // MARK: `Property` Requirements @@ -51,9 +34,7 @@ public final class OptionalCMQuaternionProperty: UpdatableProperty, PropertiesPr /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -69,8 +50,10 @@ public final class OptionalCMQuaternionProperty: UpdatableProperty, PropertiesPr // MARK: Initialisers public required init( - displayName: String, value: Value = nil, - formatter: CMQuaternionFormatter = CMQuaternionFormatter(), date: Date = Date() + displayName: String, + value: Value = nil, + formatter: CMQuaternionFormatter = CMQuaternionFormatter(), + date: Date = Date() ) { self.displayName = displayName self.formatter = formatter @@ -85,8 +68,7 @@ public final class OptionalCMQuaternionProperty: UpdatableProperty, PropertiesPr // MARK: Update Functions - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateValue(value?.x, date: date) _y.updateValue(value?.y, date: date) _z.updateValue(value?.z, date: date) diff --git a/Sources/GatheredKitMotion/Properties/OptionalCMRotationRateProperty.swift b/Sources/GatheredKitMotion/Properties/OptionalCMRotationRateProperty.swift index fa22d215..240ea2c4 100644 --- a/Sources/GatheredKitMotion/Properties/OptionalCMRotationRateProperty.swift +++ b/Sources/GatheredKitMotion/Properties/OptionalCMRotationRateProperty.swift @@ -8,28 +8,19 @@ public final class OptionalCMRotationRateProperty: UpdatableProperty, Properties public typealias Value = CMRotationRate? public typealias Formatter = CMRotationRateFormatter - public var allProperties: [AnyProperty] { - return [$x, $y, $z] - } + public var allProperties: [AnyProperty] { return [$x, $y, $z] } - @OptionalFrequencyProperty - public private(set) var x: Measurement? + @OptionalFrequencyProperty public private(set) var x: Measurement? - @OptionalFrequencyProperty - public private(set) var y: Measurement? + @OptionalFrequencyProperty public private(set) var y: Measurement? - @OptionalFrequencyProperty - public private(set) var z: Measurement? + @OptionalFrequencyProperty public private(set) var z: Measurement? // MARK: Property Wrapper Properties public var wrappedValue: Value { - get { - value - } - set { - updateValue(newValue) - } + get { value } + set { updateValue(newValue) } } public var projectedValue: ReadOnlyProperty { @@ -43,9 +34,7 @@ public final class OptionalCMRotationRateProperty: UpdatableProperty, Properties /// The latest snapshot of data. public internal(set) var snapshot: Snapshot { - didSet { - updateSubject.notifyUpdateListeners(of: snapshot) - } + didSet { updateSubject.notifyUpdateListeners(of: snapshot) } } /// A formatter that can be used to build a human-friendly string from the @@ -61,7 +50,9 @@ public final class OptionalCMRotationRateProperty: UpdatableProperty, Properties // MARK: Initialisers public required init( - displayName: String, value: Value = nil, formatter: Formatter = Formatter(), + displayName: String, + value: Value = nil, + formatter: Formatter = Formatter(), date: Date = Date() ) { self.displayName = displayName @@ -74,8 +65,7 @@ public final class OptionalCMRotationRateProperty: UpdatableProperty, Properties _z = .radiansPerSecond(displayName: "z", value: value?.z, date: date) } - @discardableResult - public func updateValue(_ value: Value, date: Date) -> Snapshot { + @discardableResult public func updateValue(_ value: Value, date: Date) -> Snapshot { _x.updateMeasuredValue(value?.x, date: date) _y.updateMeasuredValue(value?.y, date: date) _z.updateMeasuredValue(value?.z, date: date) diff --git a/Sources/GatheredKitMotion/Sources/Accelerometer.swift b/Sources/GatheredKitMotion/Sources/Accelerometer.swift index a24fa01f..3e92f8ea 100644 --- a/Sources/GatheredKitMotion/Sources/Accelerometer.swift +++ b/Sources/GatheredKitMotion/Sources/Accelerometer.swift @@ -29,20 +29,15 @@ public final class Accelerometer: UpdatingSource, CustomisableUpdateIntervalCont return isUpdating ? CMMotionManager.shared.accelerometerUpdateInterval : nil } - @OptionalCMAccelerationProperty - public private(set) var acceleration: CMAcceleration? + @OptionalCMAccelerationProperty public private(set) var acceleration: CMAcceleration? - public var allProperties: [AnyProperty] { - return [$acceleration] - } + public var allProperties: [AnyProperty] { return [$acceleration] } private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } @@ -53,9 +48,7 @@ public final class Accelerometer: UpdatingSource, CustomisableUpdateIntervalCont sourceEventsSubject = .init() } - public func startUpdating( - every updateInterval: TimeInterval - ) { + public func startUpdating(every updateInterval: TimeInterval) { let motionManager = CMMotionManager.shared motionManager.accelerometerUpdateInterval = updateInterval @@ -67,14 +60,15 @@ public final class Accelerometer: UpdatingSource, CustomisableUpdateIntervalCont guard let self = self else { return } if let error = error { CMMotionManager.shared.stopAccelerometerUpdates() - self.sourceEventsSubject.notifyUpdateListeners( - of: .stoppedUpdating(error: error)) + self.sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating(error: error)) self.state = .notMonitoring return } guard let data = data else { return } let snapshot = self._acceleration.updateValue(data.acceleration, date: data.date) - self.sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: self.$acceleration, snapshot: snapshot)) + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$acceleration, snapshot: snapshot) + ) } state = .monitoring(updatesQueue: updatesQueue) diff --git a/Sources/GatheredKitMotion/Sources/Altimeter.swift b/Sources/GatheredKitMotion/Sources/Altimeter.swift index 986edcea..2e6e29da 100644 --- a/Sources/GatheredKitMotion/Sources/Altimeter.swift +++ b/Sources/GatheredKitMotion/Sources/Altimeter.swift @@ -23,35 +23,30 @@ public final class Altimeter: UpdatingSource, Controllable, ActionProvider { public private(set) var isUpdating: Bool = false - @OptionalLengthProperty - public private(set) var relativeAltitude: Measurement? - @OptionalPressureProperty - public private(set) var pressure: Measurement? + @OptionalLengthProperty public private(set) var relativeAltitude: Measurement? + @OptionalPressureProperty public private(set) var pressure: Measurement? - public var allProperties: [AnyProperty] { - return [$relativeAltitude, $pressure] - } + public var allProperties: [AnyProperty] { return [$relativeAltitude, $pressure] } public var actions: [Action] { return [ Action( - title: "Reset Altitude", isAvailable: isUpdating, - perform: { [weak self] in - guard let self = self else { return } + title: "Reset Altitude", + isAvailable: isUpdating, + perform: { [weak self] in guard let self = self else { return } guard self.isUpdating else { return } self.stopUpdating() self.startUpdating() - }) + } + ) ] } private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } @@ -70,27 +65,22 @@ public final class Altimeter: UpdatingSource, Controllable, ActionProvider { availability = CMAltimeter.availability if availability != oldAvailability { - sourceEventsSubject.notifyUpdateListeners( - of: .availabilityUpdated(availability)) + sourceEventsSubject.notifyUpdateListeners(of: .availabilityUpdated(availability)) } switch availability { - case .available: - break + case .available: break case .permissionDenied: - sourceEventsSubject.notifyUpdateListeners( - of: .failedToStart(error: .permissionDenied)) + sourceEventsSubject.notifyUpdateListeners(of: .failedToStart(error: .permissionDenied)) return case .requiresPermissionsPrompt: // Perhaps it will ask the user when `startRelativeAltitudeUpdates` is called? break case .restricted: - sourceEventsSubject.notifyUpdateListeners( - of: .failedToStart(error: .restricted)) + sourceEventsSubject.notifyUpdateListeners(of: .failedToStart(error: .restricted)) return case .unavailable: - sourceEventsSubject.notifyUpdateListeners( - of: .failedToStart(error: .unavailable)) + sourceEventsSubject.notifyUpdateListeners(of: .failedToStart(error: .unavailable)) return } @@ -99,12 +89,10 @@ public final class Altimeter: UpdatingSource, Controllable, ActionProvider { let altimeter = CMAltimeter() altimeter.startRelativeAltitudeUpdates(to: updatesQueue) { - [weak self, weak altimeter] data, error in - guard let self = self else { return } + [weak self, weak altimeter] data, error in guard let self = self else { return } if let error = error { altimeter?.stopRelativeAltitudeUpdates() - self.sourceEventsSubject.notifyUpdateListeners( - of: .stoppedUpdating(error: error)) + self.sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating(error: error)) self.state = .notMonitoring return } @@ -130,22 +118,15 @@ public final class Altimeter: UpdatingSource, Controllable, ActionProvider { extension CMAltimeter { fileprivate static var availability: SourceAvailability { - guard isRelativeAltitudeAvailable() else { - return .unavailable - } + guard isRelativeAltitudeAvailable() else { return .unavailable } let authorizationStatus = self.authorizationStatus() switch authorizationStatus { - case .authorized: - return .available - case .denied: - return .permissionDenied - case .notDetermined: - return .requiresPermissionsPrompt - case .restricted: - return .restricted - @unknown default: - return .unavailable + case .authorized: return .available + case .denied: return .permissionDenied + case .notDetermined: return .requiresPermissionsPrompt + case .restricted: return .restricted + @unknown default: return .unavailable } } diff --git a/Sources/GatheredKitMotion/Sources/CMLogItem+date.swift b/Sources/GatheredKitMotion/Sources/CMLogItem+date.swift index 81784321..86eb8c4e 100644 --- a/Sources/GatheredKitMotion/Sources/CMLogItem+date.swift +++ b/Sources/GatheredKitMotion/Sources/CMLogItem+date.swift @@ -7,9 +7,7 @@ private var deviceBootTime: Date = { extension CMLogItem { - internal var date: Date { - return Date(timeInterval: timestamp, since: deviceBootTime) - } + internal var date: Date { return Date(timeInterval: timestamp, since: deviceBootTime) } } #endif diff --git a/Sources/GatheredKitMotion/Sources/DeviceMotion.swift b/Sources/GatheredKitMotion/Sources/DeviceMotion.swift index b97dd5c0..df07ce5a 100644 --- a/Sources/GatheredKitMotion/Sources/DeviceMotion.swift +++ b/Sources/GatheredKitMotion/Sources/DeviceMotion.swift @@ -33,42 +33,28 @@ public final class DeviceMotion: UpdatingSource, CustomisableUpdateIntervalContr return isUpdating ? CMMotionManager.shared.deviceMotionUpdateInterval : nil } - @OptionalCMAttitudeProperty - public private(set) var attitude: CMAttitude? + @OptionalCMAttitudeProperty public private(set) var attitude: CMAttitude? - @OptionalCMAccelerationProperty - public private(set) var gravity: CMAcceleration? + @OptionalCMAccelerationProperty public private(set) var gravity: CMAcceleration? - @OptionalCMAccelerationProperty - public private(set) var userAcceleration: CMAcceleration? + @OptionalCMAccelerationProperty public private(set) var userAcceleration: CMAcceleration? - @OptionalAngleProperty - public private(set) var heading: Measurement? + @OptionalAngleProperty public private(set) var heading: Measurement? - @OptionalCMCalibratedMagneticFieldProperty - public private(set) var magneticField: CMCalibratedMagneticField? + @OptionalCMCalibratedMagneticFieldProperty public private(set) var magneticField: + CMCalibratedMagneticField? - @OptionalCMRotationRateProperty - public private(set) var rotationRate: CMRotationRate? + @OptionalCMRotationRateProperty public private(set) var rotationRate: CMRotationRate? public var allProperties: [AnyProperty] { - return [ - $attitude, - $gravity, - $userAcceleration, - $heading, - $magneticField, - $rotationRate, - ] + return [$attitude, $gravity, $userAcceleration, $heading, $magneticField, $rotationRate] } private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } @@ -106,8 +92,7 @@ public final class DeviceMotion: UpdatingSource, CustomisableUpdateIntervalContr if let error = error { CMMotionManager.shared.stopDeviceMotionUpdates() - self.sourceEventsSubject.notifyUpdateListeners( - of: .stoppedUpdating(error: error)) + self.sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating(error: error)) self.state = .notMonitoring return } @@ -137,10 +122,7 @@ public final class DeviceMotion: UpdatingSource, CustomisableUpdateIntervalContr withHandler: handler ) } else { - motionManager.startDeviceMotionUpdates( - to: updatesQueue, - withHandler: handler - ) + motionManager.startDeviceMotionUpdates(to: updatesQueue, withHandler: handler) } state = .monitoring(updatesQueue: updatesQueue) diff --git a/Sources/GatheredKitMotion/Sources/Gyroscope.swift b/Sources/GatheredKitMotion/Sources/Gyroscope.swift index efe95148..46283723 100644 --- a/Sources/GatheredKitMotion/Sources/Gyroscope.swift +++ b/Sources/GatheredKitMotion/Sources/Gyroscope.swift @@ -29,20 +29,15 @@ public final class Gyroscope: UpdatingSource, CustomisableUpdateIntervalControll return isUpdating ? CMMotionManager.shared.gyroUpdateInterval : nil } - @OptionalCMRotationRateProperty - public private(set) var rotationRate: CMRotationRate? + @OptionalCMRotationRateProperty public private(set) var rotationRate: CMRotationRate? - public var allProperties: [AnyProperty] { - return [$rotationRate] - } + public var allProperties: [AnyProperty] { return [$rotationRate] } private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } @@ -53,9 +48,7 @@ public final class Gyroscope: UpdatingSource, CustomisableUpdateIntervalControll sourceEventsSubject = .init() } - public func startUpdating( - every updateInterval: TimeInterval - ) { + public func startUpdating(every updateInterval: TimeInterval) { let motionManager = CMMotionManager.shared motionManager.gyroUpdateInterval = updateInterval @@ -68,8 +61,7 @@ public final class Gyroscope: UpdatingSource, CustomisableUpdateIntervalControll if let error = error { CMMotionManager.shared.stopGyroUpdates() - self.sourceEventsSubject.notifyUpdateListeners( - of: .stoppedUpdating(error: error)) + self.sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating(error: error)) self.state = .notMonitoring return } diff --git a/Sources/GatheredKitMotion/Sources/Magnetometer.swift b/Sources/GatheredKitMotion/Sources/Magnetometer.swift index 4cb1d299..39c0db1b 100644 --- a/Sources/GatheredKitMotion/Sources/Magnetometer.swift +++ b/Sources/GatheredKitMotion/Sources/Magnetometer.swift @@ -29,20 +29,15 @@ public final class Magnetometer: UpdatingSource, CustomisableUpdateIntervalContr return isUpdating ? CMMotionManager.shared.magnetometerUpdateInterval : nil } - @OptionalCMMagneticFieldProperty - public private(set) var magneticField: CMMagneticField? + @OptionalCMMagneticFieldProperty public private(set) var magneticField: CMMagneticField? - public var allProperties: [AnyProperty] { - return [$magneticField] - } + public var allProperties: [AnyProperty] { return [$magneticField] } private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } @@ -53,9 +48,7 @@ public final class Magnetometer: UpdatingSource, CustomisableUpdateIntervalContr sourceEventsSubject = .init() } - public func startUpdating( - every updateInterval: TimeInterval - ) { + public func startUpdating(every updateInterval: TimeInterval) { let motionManager = CMMotionManager.shared motionManager.magnetometerUpdateInterval = updateInterval @@ -68,8 +61,7 @@ public final class Magnetometer: UpdatingSource, CustomisableUpdateIntervalContr if let error = error { CMMotionManager.shared.stopMagnetometerUpdates() - self.sourceEventsSubject.notifyUpdateListeners( - of: .stoppedUpdating(error: error)) + self.sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating(error: error)) self.state = .notMonitoring return } diff --git a/Sources/GatheredKitScreen/ScreenProvider_iOS_tvOS.swift b/Sources/GatheredKitScreen/ScreenProvider_iOS_tvOS.swift index ca9ba2c0..1f406a9b 100644 --- a/Sources/GatheredKitScreen/ScreenProvider_iOS_tvOS.swift +++ b/Sources/GatheredKitScreen/ScreenProvider_iOS_tvOS.swift @@ -30,25 +30,19 @@ public final class ScreenProvider: UpdatingSourceProvider, ControllableSourcePro private var state: State = .notMonitoring { didSet { switch state { - case .monitoring: - isUpdating = true - case .notMonitoring: - isUpdating = false + case .monitoring: isUpdating = true + case .notMonitoring: isUpdating = false } } } private let notificationCenter: NotificationCenter - public convenience init() { - self.init(notificationCenter: .default) - } + public convenience init() { self.init(notificationCenter: .default) } internal required init(notificationCenter: NotificationCenter) { self.notificationCenter = notificationCenter - sources = UIScreen.screens.map { uiScreen in - Screen(screen: uiScreen) - } + sources = UIScreen.screens.map { uiScreen in Screen(screen: uiScreen) } sourceProviderEventsSubject = .init() } @@ -92,7 +86,10 @@ public final class ScreenProvider: UpdatingSourceProvider, ControllableSourcePro state = .monitoring( observers: .init( - didConnect: didConnectCancellable, didDisconnect: didDisconnectCancellable)) + didConnect: didConnectCancellable, + didDisconnect: didDisconnectCancellable + ) + ) sourceProviderEventsSubject.notifyUpdateListeners(of: .startedUpdating) } diff --git a/Sources/GatheredKitScreen/Screen_iOS_tvOS.swift b/Sources/GatheredKitScreen/Screen_iOS_tvOS.swift index 02a6b359..1932ccfb 100644 --- a/Sources/GatheredKitScreen/Screen_iOS_tvOS.swift +++ b/Sources/GatheredKitScreen/Screen_iOS_tvOS.swift @@ -11,8 +11,10 @@ public final class Screen: UpdatingSource, Controllable { // swiftlint:disable duplicate_enum_cases #if os(iOS) case monitoring( - brightnessChangeObeserver: NSObjectProtocol?, modeChangeObeserver: NSObjectProtocol, - updatesQueue: OperationQueue) + brightnessChangeObeserver: NSObjectProtocol?, + modeChangeObeserver: NSObjectProtocol, + updatesQueue: OperationQueue + ) #elseif os(tvOS) case monitoring(modeChangeObeserver: NSObjectProtocol, updatesQueue: OperationQueue) #endif @@ -31,10 +33,8 @@ public final class Screen: UpdatingSource, Controllable { /// A boolean indicating if the screen is monitoring for brightness changes public var isUpdating: Bool { switch state { - case .notMonitoring: - return false - case .monitoring: - return true + case .notMonitoring: return false + case .monitoring: return true } } @@ -44,36 +44,31 @@ public final class Screen: UpdatingSource, Controllable { /** The reported resolution of the screen */ - @SizeProperty - public private(set) var reportedResolution: CGSize + @SizeProperty public private(set) var reportedResolution: CGSize /** The native resolution of the screen */ - @SizeProperty - public private(set) var nativeResolution: CGSize + @SizeProperty public private(set) var nativeResolution: CGSize /** The reported scale factor of the screen */ - @ScaleProperty - public private(set) var reportedScale: CGFloat + @ScaleProperty public private(set) var reportedScale: CGFloat /** The native scale factor of the screen */ - @ScaleProperty - public private(set) var nativeScale: CGFloat + @ScaleProperty public private(set) var nativeScale: CGFloat #if os(iOS) /** The brightness level of the screen. The value of this property will be a number between 0.0 and 1.0, inclusive. - + If the screen is not the main screen this value will always be 1. */ - @PercentProperty - public private(set) var brightness: CGFloat + @PercentProperty public private(set) var brightness: CGFloat #endif /** @@ -86,20 +81,9 @@ public final class Screen: UpdatingSource, Controllable { */ public var allProperties: [AnyProperty] { #if os(iOS) - return [ - $reportedResolution, - $nativeResolution, - $reportedScale, - $nativeScale, - $brightness, - ] + return [$reportedResolution, $nativeResolution, $reportedScale, $nativeScale, $brightness] #elseif os(tvOS) - return [ - $reportedResolution, - $nativeResolution, - $reportedScale, - $nativeScale, - ] + return [$reportedResolution, $nativeResolution, $reportedScale, $nativeScale] #endif } @@ -111,9 +95,7 @@ public final class Screen: UpdatingSource, Controllable { /** Create a new instance of `Screen` for the `main` `UIScreen`. */ - public convenience init() { - self.init(screen: UIScreen.main) - } + public convenience init() { self.init(screen: UIScreen.main) } /** Create a new instance of `Screen` for the given `UIScreen` instance @@ -126,25 +108,16 @@ public final class Screen: UpdatingSource, Controllable { self.uiScreen = screen self.notificationCenter = notificationCenter - _reportedResolution = .init( - displayName: "Resolution (reported)", - value: screen.bounds.size - ) + _reportedResolution = .init(displayName: "Resolution (reported)", value: screen.bounds.size) _nativeResolution = .init( displayName: "Resolution (native)", value: screen.nativeBounds.size ) - _reportedScale = .init( - displayName: "Scale (reported)", - value: screen.scale - ) + _reportedScale = .init(displayName: "Scale (reported)", value: screen.scale) - _nativeScale = .init( - displayName: "Scale (native)", - value: screen.nativeScale - ) + _nativeScale = .init(displayName: "Scale (native)", value: screen.nativeScale) #if os(iOS) let brightness = screen == .main ? screen.brightness : 1 @@ -157,9 +130,7 @@ public final class Screen: UpdatingSource, Controllable { $nativeResolution.formatter.suffix = " Pixels" } - deinit { - stopUpdating() - } + deinit { stopUpdating() } /** Start automatically monitoring changes to the source. This will start delegate methods being called @@ -179,21 +150,20 @@ public final class Screen: UpdatingSource, Controllable { forName: UIScreen.brightnessDidChangeNotification, object: uiScreen, queue: updatesQueue - ) { [weak self] _ in - guard let self = self else { return } + ) { [weak self] _ in guard let self = self else { return } - if let snapshot = self._brightness.updateValueIfDifferent(self.uiScreen.brightness) { + if let snapshot = self._brightness.updateValueIfDifferent(self.uiScreen.brightness) + { self.sourceEventsSubject.notifyUpdateListeners( - of: .propertyUpdated( - property: self.$brightness, - snapshot: snapshot - ) + of: .propertyUpdated(property: self.$brightness, snapshot: snapshot) ) } } if let snapshot = _brightness.updateValueIfDifferent(uiScreen.brightness) { - sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: $brightness, snapshot: snapshot)) + sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: $brightness, snapshot: snapshot) + ) } } else { brightnessChangeObeserver = nil @@ -201,41 +171,34 @@ public final class Screen: UpdatingSource, Controllable { #endif let modeChangeObeserver = notificationCenter.addObserver( - forName: UIScreen.modeDidChangeNotification, object: uiScreen, queue: updatesQueue - ) { [weak self] _ in - guard let self = self else { return } - if let snapshot = self._reportedResolution.updateValueIfDifferent(self.uiScreen.bounds.size) { + forName: UIScreen.modeDidChangeNotification, + object: uiScreen, + queue: updatesQueue + ) { [weak self] _ in guard let self = self else { return } + if let snapshot = self._reportedResolution.updateValueIfDifferent( + self.uiScreen.bounds.size + ) { self.sourceEventsSubject.notifyUpdateListeners( - of: .propertyUpdated( - property: self.$reportedResolution, - snapshot: snapshot - ) + of: .propertyUpdated(property: self.$reportedResolution, snapshot: snapshot) + ) + } + if let snapshot = self._nativeResolution.updateValueIfDifferent( + self.uiScreen.nativeBounds.size + ) { + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$nativeResolution, snapshot: snapshot) + ) + } + if let snapshot = self._reportedScale.updateValueIfDifferent(self.uiScreen.scale) { + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$reportedResolution, snapshot: snapshot) + ) + } + if let snapshot = self._nativeScale.updateValueIfDifferent(self.uiScreen.nativeScale) { + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$nativeScale, snapshot: snapshot) ) } - if let snapshot = self._nativeResolution.updateValueIfDifferent(self.uiScreen.nativeBounds.size) { - self.sourceEventsSubject.notifyUpdateListeners( - of: .propertyUpdated( - property: self.$nativeResolution, - snapshot: snapshot - ) - ) - } - if let snapshot = self._reportedScale.updateValueIfDifferent(self.uiScreen.scale) { - self.sourceEventsSubject.notifyUpdateListeners( - of: .propertyUpdated( - property: self.$reportedResolution, - snapshot: snapshot - ) - ) - } - if let snapshot = self._nativeScale.updateValueIfDifferent(self.uiScreen.nativeScale) { - self.sourceEventsSubject.notifyUpdateListeners( - of: .propertyUpdated( - property: self.$nativeScale, - snapshot: snapshot - ) - ) - } } _reportedResolution.updateValueIfDifferent(uiScreen.bounds.size) @@ -250,10 +213,7 @@ public final class Screen: UpdatingSource, Controllable { updatesQueue: updatesQueue ) #elseif os(tvOS) - state = .monitoring( - modeChangeObeserver: modeChangeObeserver, - updatesQueue: updatesQueue - ) + state = .monitoring(modeChangeObeserver: modeChangeObeserver, updatesQueue: updatesQueue) #endif sourceEventsSubject.notifyUpdateListeners(of: .startedUpdating) @@ -268,23 +228,21 @@ public final class Screen: UpdatingSource, Controllable { else { return } brightnessChangeObeserver.map { brightnessChangeObeserver in - notificationCenter - .removeObserver( - brightnessChangeObeserver, - name: UIScreen.brightnessDidChangeNotification, - object: uiScreen - ) + notificationCenter.removeObserver( + brightnessChangeObeserver, + name: UIScreen.brightnessDidChangeNotification, + object: uiScreen + ) } #elseif os(tvOS) guard case .monitoring(let modeChangeObeserver, _) = state else { return } #endif - notificationCenter - .removeObserver( - modeChangeObeserver, - name: UIScreen.modeDidChangeNotification, - object: uiScreen - ) + notificationCenter.removeObserver( + modeChangeObeserver, + name: UIScreen.modeDidChangeNotification, + object: uiScreen + ) state = .notMonitoring sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating()) diff --git a/Sources/GatheredKitScreen/Screen_macOS.swift b/Sources/GatheredKitScreen/Screen_macOS.swift index f4c05a5a..d3624753 100644 --- a/Sources/GatheredKitScreen/Screen_macOS.swift +++ b/Sources/GatheredKitScreen/Screen_macOS.swift @@ -9,8 +9,10 @@ public final class Screen: UpdatingSource, Controllable { private enum State { case notMonitoring case monitoring( - screenParametersObserver: NSObjectProtocol, colorSpaceObserver: NSObjectProtocol, - updatesQueue: OperationQueue) + screenParametersObserver: NSObjectProtocol, + colorSpaceObserver: NSObjectProtocol, + updatesQueue: OperationQueue + ) } public let availability: SourceAvailability = .available @@ -31,18 +33,13 @@ public final class Screen: UpdatingSource, Controllable { /** The resolution of the screen */ - @SizeProperty - public private(set) var resolution: CGSize + @SizeProperty public private(set) var resolution: CGSize /** An array of the screen's properties, in the following order: - Resolution */ - public var allProperties: [AnyProperty] { - return [ - $resolution - ] - } + public var allProperties: [AnyProperty] { return [$resolution] } /// The internal state, indicating if the screen is monitoring for changes private var state: State = .notMonitoring { @@ -79,16 +76,11 @@ public final class Screen: UpdatingSource, Controllable { self.notificationCenter = notificationCenter sourceEventsSubject = .init() - _resolution = .init( - displayName: "Resolution", - value: screen.frame.size - ) + _resolution = .init(displayName: "Resolution", value: screen.frame.size) $resolution.formatter.suffix = " Pixels" } - deinit { - stopUpdating() - } + deinit { stopUpdating() } /** Start automatically monitoring changes to the source. This will start delegate methods being called @@ -102,23 +94,28 @@ public final class Screen: UpdatingSource, Controllable { let screenParametersObserver = notificationCenter.addObserver( forName: NSApplication.didChangeScreenParametersNotification, - object: NSApplication.shared, queue: updatesQueue - ) { [weak self] _ in - guard let self = self else { return } + object: NSApplication.shared, + queue: updatesQueue + ) { [weak self] _ in guard let self = self else { return } if let snapshot = self._resolution.updateValueIfDifferent(self.nsScreen.frame.size) { - self.sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: self.$resolution, snapshot: snapshot)) + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$resolution, snapshot: snapshot) + ) } } if let snapshot = self._resolution.updateValueIfDifferent(self.nsScreen.frame.size) { - self.sourceEventsSubject.notifyUpdateListeners(of: .propertyUpdated(property: self.$resolution, snapshot: snapshot)) + self.sourceEventsSubject.notifyUpdateListeners( + of: .propertyUpdated(property: self.$resolution, snapshot: snapshot) + ) } let colorSpaceObserver = notificationCenter.addObserver( - forName: NSScreen.colorSpaceDidChangeNotification, object: nsScreen, queue: updatesQueue - ) { _ in - // TODO: Update colour space + forName: NSScreen.colorSpaceDidChangeNotification, + object: nsScreen, + queue: updatesQueue + ) { _ in // TODO: Update colour space } state = .monitoring( @@ -136,19 +133,17 @@ public final class Screen: UpdatingSource, Controllable { guard case .monitoring(let screenParametersObserver, let colorSpaceObserver, _) = state else { return } - notificationCenter - .removeObserver( - screenParametersObserver, - name: NSApplication.didChangeScreenParametersNotification, - object: NSApplication.shared - ) + notificationCenter.removeObserver( + screenParametersObserver, + name: NSApplication.didChangeScreenParametersNotification, + object: NSApplication.shared + ) - notificationCenter - .removeObserver( - colorSpaceObserver, - name: NSScreen.colorSpaceDidChangeNotification, - object: nsScreen - ) + notificationCenter.removeObserver( + colorSpaceObserver, + name: NSScreen.colorSpaceDidChangeNotification, + object: nsScreen + ) state = .notMonitoring sourceEventsSubject.notifyUpdateListeners(of: .stoppedUpdating()) diff --git a/Sources/GatheredKitScreen/Screen_watchOS.swift b/Sources/GatheredKitScreen/Screen_watchOS.swift index a6fd084a..5d2d2bbc 100644 --- a/Sources/GatheredKitScreen/Screen_watchOS.swift +++ b/Sources/GatheredKitScreen/Screen_watchOS.swift @@ -16,33 +16,24 @@ public final class Screen: Source { /** The native resolution of the screen */ - @SizeProperty - public private(set) var resolution: CGSize + @SizeProperty public private(set) var resolution: CGSize /** The native scale factor of the screen */ - @ScaleProperty - public private(set) var scale: CGFloat + @ScaleProperty public private(set) var scale: CGFloat /** An array of the screen's properties, in the following order: - Resolution - Scale */ - public var allProperties: [AnyProperty] { - return [ - $resolution, - $scale, - ] - } + public var allProperties: [AnyProperty] { return [$resolution, $scale] } /** Create a new instance of `Screen` for the `current` `WKInterfaceDevice`. */ - public convenience init() { - self.init(device: .current()) - } + public convenience init() { self.init(device: .current()) } /** Create a new instance of `Screen` for the given `WKInterfaceDevice` instance. @@ -52,15 +43,9 @@ public final class Screen: Source { internal init(device: WKInterfaceDevice) { self.device = device - _resolution = .init( - displayName: "Resolution", - value: device.screenBounds.size - ) + _resolution = .init(displayName: "Resolution", value: device.screenBounds.size) - _scale = .init( - displayName: "Scale", - value: device.screenScale - ) + _scale = .init(displayName: "Scale", value: device.screenScale) $resolution.formatter.suffix = " Points" } diff --git a/Sources/GatheredKitTestHelpers/Mocks/MockNotificationCenter.swift b/Sources/GatheredKitTestHelpers/Mocks/MockNotificationCenter.swift index 1acd502b..03be2247 100644 --- a/Sources/GatheredKitTestHelpers/Mocks/MockNotificationCenter.swift +++ b/Sources/GatheredKitTestHelpers/Mocks/MockNotificationCenter.swift @@ -21,17 +21,11 @@ public final class MockNotificationCenter: NotificationCenter { return addObserverParameters.map { $0.name } } - public var latestAddObserverObject: Any?? { - return addObserverParameters.last?.object - } + public var latestAddObserverObject: Any?? { return addObserverParameters.last?.object } - public var addObserverObjects: [Any?] { - return addObserverParameters.map { $0.object } - } + public var addObserverObjects: [Any?] { return addObserverParameters.map { $0.object } } - public var latestAddObserverQueue: OperationQueue?? { - return addObserverParameters.last?.queue - } + public var latestAddObserverQueue: OperationQueue?? { return addObserverParameters.last?.queue } public var addObserverQueues: [OperationQueue?] { return addObserverParameters.map { $0.queue } @@ -51,9 +45,7 @@ public final class MockNotificationCenter: NotificationCenter { public private(set) var addObserverOpaqueObjects: [NSObjectProtocol] = [] - public var addObserverHasBeenCalled: Bool { - return !addObserverParameters.isEmpty - } + public var addObserverHasBeenCalled: Bool { return !addObserverParameters.isEmpty } public private(set) var addObserverCallCount = 0 public private(set) var removeObserverParameters: [RemoveObserverParameters] = [] @@ -63,12 +55,12 @@ public final class MockNotificationCenter: NotificationCenter { } public override func addObserver( - forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, + forName name: Notification.Name?, + object obj: Any?, + queue: OperationQueue?, using block: @escaping (Notification) -> Void ) -> NSObjectProtocol { - defer { - addObserverCallCount += 1 - } + defer { addObserverCallCount += 1 } addObserverParameters.append((name: name, object: obj, queue: queue, block: block)) @@ -78,7 +70,9 @@ public final class MockNotificationCenter: NotificationCenter { } public override func removeObserver( - _ observer: Any, name aName: NSNotification.Name?, object anObject: Any? + _ observer: Any, + name aName: NSNotification.Name?, + object anObject: Any? ) { let parameters = RemoveObserverParameters(observer, aName, anObject) removeObserverParameters.append(parameters) diff --git a/Tests/GatheredKitLocationTests/LocationTests.swift b/Tests/GatheredKitLocationTests/LocationTests.swift index 569bd523..73e0c9b5 100644 --- a/Tests/GatheredKitLocationTests/LocationTests.swift +++ b/Tests/GatheredKitLocationTests/LocationTests.swift @@ -177,7 +177,7 @@ // expect(Location.availability).to(equal(.available)) // } // } -// +// // } // // } diff --git a/Tests/GatheredKitScreenTests/MockScreen.swift b/Tests/GatheredKitScreenTests/MockScreen.swift index 7f0d6441..23e5c3f1 100644 --- a/Tests/GatheredKitScreenTests/MockScreen.swift +++ b/Tests/GatheredKitScreenTests/MockScreen.swift @@ -35,57 +35,37 @@ final class MockScreen: UIScreen { private var _bounds: CGRect? override var bounds: CGRect { - get { - return _bounds ?? super.bounds - } - set { - _bounds = newValue - } + get { return _bounds ?? super.bounds } + set { _bounds = newValue } } private var _nativeBounds: CGRect? override var nativeBounds: CGRect { - get { - return _nativeBounds ?? super.nativeBounds - } - set { - _nativeBounds = newValue - } + get { return _nativeBounds ?? super.nativeBounds } + set { _nativeBounds = newValue } } private var _scale: CGFloat? override var scale: CGFloat { - get { - return _scale ?? super.scale - } - set { - _scale = newValue - } + get { return _scale ?? super.scale } + set { _scale = newValue } } private var _nativeScale: CGFloat? override var nativeScale: CGFloat { - get { - return _nativeScale ?? super.nativeScale - } - set { - _nativeScale = newValue - } + get { return _nativeScale ?? super.nativeScale } + set { _nativeScale = newValue } } #if os(iOS) private var _brightness: CGFloat? override var brightness: CGFloat { - get { - return _brightness ?? super.brightness - } - set { - _brightness = newValue - } + get { return _brightness ?? super.brightness } + set { _brightness = newValue } } #endif diff --git a/Tests/GatheredKitScreenTests/ScreenTests_iOS_tvOS.swift b/Tests/GatheredKitScreenTests/ScreenTests_iOS_tvOS.swift index 1b11be22..07f14b10 100644 --- a/Tests/GatheredKitScreenTests/ScreenTests_iOS_tvOS.swift +++ b/Tests/GatheredKitScreenTests/ScreenTests_iOS_tvOS.swift @@ -31,15 +31,11 @@ final class ScreenTests: XCTestCase { expectation.assertForOverFulfill = true expectation.expectedFulfillmentCount = 1 let cancellable = screen.sourceEventPublisher.addUpdateListener { event in - defer { - expectation.fulfill() - } + defer { expectation.fulfill() } switch event { - case .startedUpdating: - break - default: - XCTFail("Should only publish the `startedUpdating") + case .startedUpdating: break + default: XCTFail("Should only publish the `startedUpdating") } } _ = cancellable @@ -50,17 +46,21 @@ final class ScreenTests: XCTestCase { #if os(iOS) XCTAssertEqual(notificationCenter.addObserverCallCount, 2) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.brightnessDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.brightnessDidChangeNotification) + ) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification) + ) #elseif os(tvOS) XCTAssertEqual(notificationCenter.addObserverCallCount, 1) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification) + ) #endif XCTAssertEqual( Set(notificationCenter.addObserverParameters.map { $0.object as? UIScreen }), - Set([uiScreen])) + Set([uiScreen]) + ) screen.startUpdating() @@ -88,21 +88,20 @@ final class ScreenTests: XCTestCase { let uiScreen = UIScreen.main let screen = Screen(screen: uiScreen, notificationCenter: notificationCenter) let startUpdatingEventExpectation = XCTestExpectation( - description: "Should publish a start updating event") + description: "Should publish a start updating event" + ) startUpdatingEventExpectation.assertForOverFulfill = true startUpdatingEventExpectation.expectedFulfillmentCount = 1 let stopUpdatingEventExpectation = XCTestExpectation( - description: "Should publish a stop updating event") + description: "Should publish a stop updating event" + ) stopUpdatingEventExpectation.assertForOverFulfill = true stopUpdatingEventExpectation.expectedFulfillmentCount = 1 let cancellable = screen.sourceEventPublisher.addUpdateListener { event in switch event { - case .startedUpdating: - startUpdatingEventExpectation.fulfill() - case .stoppedUpdating: - stopUpdatingEventExpectation.fulfill() - default: - XCTFail("Should never send \(event) event") + case .startedUpdating: startUpdatingEventExpectation.fulfill() + case .stoppedUpdating: stopUpdatingEventExpectation.fulfill() + default: XCTFail("Should never send \(event) event") } } // Shutup Xcode @@ -118,30 +117,39 @@ final class ScreenTests: XCTestCase { #if os(iOS) XCTAssertEqual(notificationCenter.addObserverCallCount, 2) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.brightnessDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.brightnessDidChangeNotification) + ) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification) + ) XCTAssertEqual(notificationCenter.removeObserverParameters.count, 2) XCTAssertTrue( notificationCenter.removeObserverNames.contains( - UIScreen.brightnessDidChangeNotification)) + UIScreen.brightnessDidChangeNotification + ) + ) XCTAssertTrue( - notificationCenter.removeObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.removeObserverNames.contains(UIScreen.modeDidChangeNotification) + ) #elseif os(tvOS) XCTAssertEqual(notificationCenter.addObserverCallCount, 1) XCTAssertTrue( - notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.addObserverNames.contains(UIScreen.modeDidChangeNotification) + ) XCTAssertEqual(notificationCenter.removeObserverParameters.count, 1) XCTAssertTrue( - notificationCenter.removeObserverNames.contains(UIScreen.modeDidChangeNotification)) + notificationCenter.removeObserverNames.contains(UIScreen.modeDidChangeNotification) + ) #endif XCTAssertEqual( Set(notificationCenter.addObserverParameters.map { $0.object as? UIScreen }), - Set([uiScreen])) + Set([uiScreen]) + ) XCTAssertEqual( Set(notificationCenter.removeObserverParameters.map { $0.object as? UIScreen }), - Set([uiScreen])) + Set([uiScreen]) + ) wait(for: [startUpdatingEventExpectation], timeout: 0.01) } @@ -152,43 +160,42 @@ final class ScreenTests: XCTestCase { let screen = Screen(screen: uiScreen, notificationCenter: notificationCenter) let reportedResolutionExpectation = XCTestExpectation( - description: "Subscriber should be called with updated reported resolution") + description: "Subscriber should be called with updated reported resolution" + ) reportedResolutionExpectation.expectedFulfillmentCount = 1 reportedResolutionExpectation.assertForOverFulfill = true let reportedResolutionCancellable = screen.$reportedResolution.updatePublisher - .addUpdateListener { reportedResolution in - reportedResolutionExpectation.fulfill() + .addUpdateListener { reportedResolution in reportedResolutionExpectation.fulfill() XCTAssertEqual(reportedResolution.value, uiScreen.bounds.size) } let nativeResolutionExpectation = XCTestExpectation( - description: "Subscriber should be called with updated native resolution") + description: "Subscriber should be called with updated native resolution" + ) nativeResolutionExpectation.expectedFulfillmentCount = 1 nativeResolutionExpectation.assertForOverFulfill = true let nativeResolutionCancellable = screen.$nativeResolution.updatePublisher.addUpdateListener - { - nativeResolution in - nativeResolutionExpectation.fulfill() + { nativeResolution in nativeResolutionExpectation.fulfill() XCTAssertEqual(nativeResolution.value, uiScreen.nativeBounds.size) } let reportedScaleExpectation = XCTestExpectation( - description: "Subscriber should be called with updated reported scale") + description: "Subscriber should be called with updated reported scale" + ) reportedScaleExpectation.expectedFulfillmentCount = 1 reportedScaleExpectation.assertForOverFulfill = true let reportedScaleCancellable = screen.$reportedScale.updatePublisher.addUpdateListener { - reportedScale in - reportedScaleExpectation.fulfill() + reportedScale in reportedScaleExpectation.fulfill() XCTAssertEqual(reportedScale.value, uiScreen.scale) } let nativeScaleExpectation = XCTestExpectation( - description: "Subscriber should be called with updated native scale") + description: "Subscriber should be called with updated native scale" + ) nativeScaleExpectation.expectedFulfillmentCount = 1 nativeScaleExpectation.assertForOverFulfill = true let nativeScaleCancellable = screen.$nativeScale.updatePublisher.addUpdateListener { - nativeScale in - nativeScaleExpectation.fulfill() + nativeScale in nativeScaleExpectation.fulfill() XCTAssertEqual(nativeScale.value, uiScreen.nativeScale) } @@ -211,10 +218,8 @@ final class ScreenTests: XCTestCase { wait( for: [ - reportedResolutionExpectation, - nativeResolutionExpectation, - reportedScaleExpectation, - nativeScaleExpectation, + reportedResolutionExpectation, nativeResolutionExpectation, + reportedScaleExpectation, nativeScaleExpectation, ], timeout: 0.01 ) @@ -229,11 +234,11 @@ final class ScreenTests: XCTestCase { let screen = Screen(screen: uiScreen, notificationCenter: notificationCenter) let brightnessExpectation = XCTestExpectation( - description: "Subscriber should be called when brightness updates") + description: "Subscriber should be called when brightness updates" + ) let brightnessCancellable = screen.$brightness.updatePublisher.addUpdateListener { - brightness in - brightnessExpectation.fulfill() + brightness in brightnessExpectation.fulfill() XCTAssertEqual(brightness.value, uiScreen.brightness) } @@ -249,12 +254,7 @@ final class ScreenTests: XCTestCase { notificationCenter.post(name: UIScreen.brightnessDidChangeNotification, object: uiScreen) XCTAssertEqual(screen.brightness, uiScreen.brightness) - wait( - for: [ - brightnessExpectation - ], - timeout: 0.1 - ) + wait(for: [brightnessExpectation], timeout: 0.1) } func testBrightnessUpdateFromDifferentScreen() { @@ -272,7 +272,9 @@ final class ScreenTests: XCTestCase { mockScreen.brightness = 0.53 notificationCenter.post( - name: UIScreen.brightnessDidChangeNotification, object: UIScreen.main) + name: UIScreen.brightnessDidChangeNotification, + object: UIScreen.main + ) wait(for: [expectation], timeout: 0.1) } diff --git a/Tests/GatheredKitTests/PlatformTests.swift b/Tests/GatheredKitTests/PlatformTests.swift index d5784908..bb9a9a78 100644 --- a/Tests/GatheredKitTests/PlatformTests.swift +++ b/Tests/GatheredKitTests/PlatformTests.swift @@ -5,24 +5,14 @@ import XCTest /// Tests to that will show which platform is being tested in the list of tests. final class PlatformTests: XCTestCase { #if os(iOS) - func test_iOS() { - XCTAssertTrue(true) - } + func test_iOS() { XCTAssertTrue(true) } #elseif targetEnvironment(macCatalyst) - func test_macCatalyst() { - XCTAssertTrue(true) - } + func test_macCatalyst() { XCTAssertTrue(true) } #elseif os(macOS) - func test_macOS() { - XCTAssertTrue(true) - } + func test_macOS() { XCTAssertTrue(true) } #elseif os(tvOS) - func test_tvOS() { - XCTAssertTrue(true) - } + func test_tvOS() { XCTAssertTrue(true) } #else - func test_unkownPlatform() { - XCTFail("Unsupported platform") - } + func test_unkownPlatform() { XCTFail("Unsupported platform") } #endif } diff --git a/scripts/format b/scripts/format new file mode 100755 index 00000000..a2b9c66b --- /dev/null +++ b/scripts/format @@ -0,0 +1,9 @@ +#!/bin/bash + +if [[ -z "${SRCROOT}" ]]; then + SRCROOT="$(dirname "$(dirname "${BASH_SOURCE[0]}")")" +fi + +# swift-format gets pretty close. The `prioritizeKeepingFunctionOutputTogether` option currently crashes (https://bugs.swift.org/browse/SR-13049) and will be added when available. +echo "$SRCROOT"/Sources/ +swift run --package-path "$SRCROOT"/DevelopmentDependencies swift-format --in-place --recursive "$SRCROOT"/Sources/ --recursive "$SRCROOT"/Tests/