From 40a98e18d0350fd1a1efa83c24aca3044b9b7bd2 Mon Sep 17 00:00:00 2001 From: Roberto Casula Date: Wed, 20 Dec 2023 13:32:48 +0100 Subject: [PATCH] Fix compilation errors with watchOS and macOS --- .../ComposableCoreLocation/Interface.swift | 550 ++++++++---------- Sources/ComposableCoreLocation/Live.swift | 4 +- 2 files changed, 253 insertions(+), 301 deletions(-) diff --git a/Sources/ComposableCoreLocation/Interface.swift b/Sources/ComposableCoreLocation/Interface.swift index ff06fd8..acc81ed 100644 --- a/Sources/ComposableCoreLocation/Interface.swift +++ b/Sources/ComposableCoreLocation/Interface.swift @@ -178,308 +178,260 @@ import CoreLocation /// write these tests, and we can test deep, subtle properties of our application. /// public struct LocationManager: Sendable { - /// Actions that correspond to `CLLocationManagerDelegate` methods. - /// - /// See `CLLocationManagerDelegate` for more information. - public enum Action: Equatable, Sendable { - case didChangeAuthorization(CLAuthorizationStatus) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didDetermineState(CLRegionState, region: Region) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didEnterRegion(Region) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didExitRegion(Region) - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didFailRanging(beaconConstraint: BeaconConstraint, error: Error) - - case didFailWithError(Error) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didFinishDeferredUpdatesWithError(Error?) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didPauseLocationUpdates - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didResumeLocationUpdates - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didStartMonitoring(region: Region) - - @available(macOS, unavailable) - @available(tvOS, unavailable) - case didUpdateHeading(newHeading: Heading) - - case didUpdateLocations([Location]) - - @available(macCatalyst, deprecated: 13) - @available(tvOS, unavailable) - case didUpdateTo(newLocation: Location, oldLocation: Location) - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didVisit(Visit) - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case monitoringDidFail(region: Region?, error: Error) - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - case didRangeBeacons([Beacon], satisfyingConstraint: BeaconConstraint) - } - - public struct Error: Swift.Error, Equatable { - public let error: NSError - - public init(_ error: Swift.Error) { - self.error = error as NSError + /// Actions that correspond to `CLLocationManagerDelegate` methods. + /// + /// See `CLLocationManagerDelegate` for more information. + public enum Action: Equatable { + case didChangeAuthorization(CLAuthorizationStatus) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didDetermineState(CLRegionState, region: Region) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didEnterRegion(Region) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didExitRegion(Region) + + @available(macOS, unavailable) + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didFailRanging(beaconConstraint: CLBeaconIdentityConstraint, error: Error) + + case didFailWithError(Error) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didFinishDeferredUpdatesWithError(Error?) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didPauseLocationUpdates + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didResumeLocationUpdates + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didStartMonitoring(region: Region) + + @available(macOS, unavailable) + @available(tvOS, unavailable) + case didUpdateHeading(newHeading: Heading) + + case didUpdateLocations([Location]) + + @available(macCatalyst, deprecated: 13) + @available(tvOS, unavailable) + case didUpdateTo(newLocation: Location, oldLocation: Location) + + @available(macOS, unavailable) + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didVisit(Visit) + + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case monitoringDidFail(region: Region?, error: Error) + + @available(macOS, unavailable) + @available(tvOS, unavailable) + @available(watchOS, unavailable) + case didRangeBeacons([Beacon], satisfyingConstraint: CLBeaconIdentityConstraint) } - } - - public var accuracyAuthorization: @Sendable () async -> AccuracyAuthorization? - - public var authorizationStatus: @Sendable () async -> CLAuthorizationStatus - - public var delegate: @Sendable () async -> AsyncStream - - @available(macOS, unavailable) - @available(tvOS, unavailable) - public var dismissHeadingCalibrationDisplay: @Sendable () async -> Void - - @available(macOS, unavailable) - @available(tvOS, unavailable) - public var heading: @Sendable () async -> Heading? - - @available(tvOS, unavailable) - public var headingAvailable: @Sendable () async -> Bool - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var isRangingAvailable: @Sendable () async -> Bool - - public var location: @Sendable () async -> Location? - - public var locationServicesEnabled: @Sendable () async -> Bool - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var maximumRegionMonitoringDistance: @Sendable () async -> CLLocationDistance - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var monitoredRegions: @Sendable () async -> Set - - @available(tvOS, unavailable) - public var requestAlwaysAuthorization: @Sendable () async -> Void - - public var requestLocation: @Sendable () async -> Void - - public var requestWhenInUseAuthorization: @Sendable () async -> Void - - public var requestTemporaryFullAccuracyAuthorization: @Sendable (String) async throws -> Void - - public var set: @Sendable (Properties) async -> Void - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var significantLocationChangeMonitoringAvailable: @Sendable () async -> Bool - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var startMonitoringForRegion: @Sendable (Region) async -> Void - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var startMonitoringSignificantLocationChanges: @Sendable () async -> Void - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var startMonitoringVisits: @Sendable () async -> Void - - @available(macOS, unavailable) - @available(tvOS, unavailable) - public var startUpdatingHeading: @Sendable () async -> Void - - @available(tvOS, unavailable) - public var startUpdatingLocation: @Sendable () async -> Void - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var stopMonitoringForRegion: @Sendable (Region) async -> Void - - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var stopMonitoringSignificantLocationChanges: @Sendable () async -> Void - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public var stopMonitoringVisits: @Sendable () async -> Void - - @available(macOS, unavailable) - @available(tvOS, unavailable) - public var stopUpdatingHeading: @Sendable () async -> Void - - public var stopUpdatingLocation: @Sendable () async -> Void - - /// Updates the given properties of a uniquely identified `CLLocationManager`. - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - @Sendable public func set( - activityType: CLActivityType? = nil, - allowsBackgroundLocationUpdates: Bool? = nil, - desiredAccuracy: CLLocationAccuracy? = nil, - distanceFilter: CLLocationDistance? = nil, - headingFilter: CLLocationDegrees? = nil, - headingOrientation: CLDeviceOrientation? = nil, - pausesLocationUpdatesAutomatically: Bool? = nil, - showsBackgroundLocationIndicator: Bool? = nil - ) async { - await self.set( - Properties( - activityType: activityType, - allowsBackgroundLocationUpdates: allowsBackgroundLocationUpdates, - desiredAccuracy: desiredAccuracy, - distanceFilter: distanceFilter, - headingFilter: headingFilter, - headingOrientation: headingOrientation, - pausesLocationUpdatesAutomatically: pausesLocationUpdatesAutomatically, - showsBackgroundLocationIndicator: showsBackgroundLocationIndicator - ) - ) - } -} - -extension LocationManager { - public struct Properties: Equatable { - @available(macOS, unavailable) - @available(tvOS, unavailable) - var activityType: CLActivityType? = nil - - @available(macOS, unavailable) - @available(tvOS, unavailable) - var allowsBackgroundLocationUpdates: Bool? = nil - - var desiredAccuracy: CLLocationAccuracy? = nil - - var distanceFilter: CLLocationDistance? = nil - - @available(macOS, unavailable) - @available(tvOS, unavailable) - var headingFilter: CLLocationDegrees? = nil - - @available(macOS, unavailable) - @available(tvOS, unavailable) - var headingOrientation: CLDeviceOrientation? = nil - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - var pausesLocationUpdatesAutomatically: Bool? = nil - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - var showsBackgroundLocationIndicator: Bool? = nil - - public static func == (lhs: Self, rhs: Self) -> Bool { - var isEqual = true - #if os(iOS) || targetEnvironment(macCatalyst) || os(watchOS) - isEqual = - isEqual - && lhs.activityType == rhs.activityType - && lhs.allowsBackgroundLocationUpdates == rhs.allowsBackgroundLocationUpdates - #endif - isEqual = - isEqual - && lhs.desiredAccuracy == rhs.desiredAccuracy - && lhs.distanceFilter == rhs.distanceFilter - #if os(iOS) || targetEnvironment(macCatalyst) || os(watchOS) - isEqual = - isEqual - && lhs.headingFilter == rhs.headingFilter - && lhs.headingOrientation == rhs.headingOrientation - #endif - #if os(iOS) || targetEnvironment(macCatalyst) - isEqual = - isEqual - && lhs.pausesLocationUpdatesAutomatically == rhs.pausesLocationUpdatesAutomatically - && lhs.showsBackgroundLocationIndicator == rhs.showsBackgroundLocationIndicator - #endif - return isEqual + + public struct Error: Swift.Error, Equatable { + public let error: NSError + + public init(_ error: Swift.Error) { + self.error = error as NSError + } } - - @available(macOS, unavailable) - @available(tvOS, unavailable) - @available(watchOS, unavailable) - public init( - activityType: CLActivityType? = nil, - allowsBackgroundLocationUpdates: Bool? = nil, - desiredAccuracy: CLLocationAccuracy? = nil, - distanceFilter: CLLocationDistance? = nil, - headingFilter: CLLocationDegrees? = nil, - headingOrientation: CLDeviceOrientation? = nil, - pausesLocationUpdatesAutomatically: Bool? = nil, - showsBackgroundLocationIndicator: Bool? = nil - ) { - self.activityType = activityType - self.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates - self.desiredAccuracy = desiredAccuracy - self.distanceFilter = distanceFilter - self.headingFilter = headingFilter - self.headingOrientation = headingOrientation - self.pausesLocationUpdatesAutomatically = pausesLocationUpdatesAutomatically - self.showsBackgroundLocationIndicator = showsBackgroundLocationIndicator - } - - @available(iOS, unavailable) - @available(macCatalyst, unavailable) - @available(watchOS, unavailable) - public init( - desiredAccuracy: CLLocationAccuracy? = nil, - distanceFilter: CLLocationDistance? = nil - ) { - self.desiredAccuracy = desiredAccuracy - self.distanceFilter = distanceFilter + + public var accuracyAuthorization: @Sendable () async -> AccuracyAuthorization? + + public var authorizationStatus: @Sendable () async -> CLAuthorizationStatus + + public var delegate: @Sendable () async -> AsyncStream + + public var dismissHeadingCalibrationDisplay: @Sendable () async -> Void + + public var heading: @Sendable () async -> Heading? + + public var headingAvailable: @Sendable () async -> Bool + + public var isRangingAvailable: @Sendable () async -> Bool + + public var location: @Sendable () async -> Location? + + public var locationServicesEnabled: @Sendable () async -> Bool + + public var maximumRegionMonitoringDistance: @Sendable () async -> CLLocationDistance + + public var monitoredRegions: @Sendable () async -> Set + + public var requestAlwaysAuthorization: @Sendable () async -> Void + + public var requestLocation: @Sendable () async -> Void + + public var requestWhenInUseAuthorization: @Sendable () async -> Void + + public var requestTemporaryFullAccuracyAuthorization: @Sendable (String) async throws -> Void + + public var set: @Sendable (Properties) async -> Void + + public var significantLocationChangeMonitoringAvailable: @Sendable () async -> Bool + + public var startMonitoringForRegion: @Sendable (Region) async -> Void + + public var startMonitoringSignificantLocationChanges: @Sendable () async -> Void + + public var startMonitoringVisits: @Sendable () async -> Void + + public var startUpdatingHeading: @Sendable () async -> Void + + public var startUpdatingLocation: @Sendable () async -> Void + + public var stopMonitoringForRegion: @Sendable (Region) async -> Void + + public var stopMonitoringSignificantLocationChanges: @Sendable () async -> Void + + public var stopMonitoringVisits: @Sendable () async -> Void + + public var stopUpdatingHeading: @Sendable () async -> Void + + public var stopUpdatingLocation: @Sendable () async -> Void + + /// Updates the given properties of a uniquely identified `CLLocationManager`. + @Sendable public func set( + activityType: CLActivityType? = nil, + allowsBackgroundLocationUpdates: Bool? = nil, + desiredAccuracy: CLLocationAccuracy? = nil, + distanceFilter: CLLocationDistance? = nil, + headingFilter: CLLocationDegrees? = nil, + headingOrientation: CLDeviceOrientation? = nil, + pausesLocationUpdatesAutomatically: Bool? = nil, + showsBackgroundLocationIndicator: Bool? = nil + ) async { + #if os(macOS) || os(tvOS) || os(watchOS) + #else + await self.set( + Properties( + activityType: activityType, + allowsBackgroundLocationUpdates: allowsBackgroundLocationUpdates, + desiredAccuracy: desiredAccuracy, + distanceFilter: distanceFilter, + headingFilter: headingFilter, + headingOrientation: headingOrientation, + pausesLocationUpdatesAutomatically: pausesLocationUpdatesAutomatically, + showsBackgroundLocationIndicator: showsBackgroundLocationIndicator + ) + ) + #endif } +} - @available(iOS, unavailable) - @available(macCatalyst, unavailable) - @available(macOS, unavailable) - @available(tvOS, unavailable) - public init( - activityType: CLActivityType? = nil, - allowsBackgroundLocationUpdates: Bool? = nil, - desiredAccuracy: CLLocationAccuracy? = nil, - distanceFilter: CLLocationDistance? = nil, - headingFilter: CLLocationDegrees? = nil, - headingOrientation: CLDeviceOrientation? = nil - ) { - self.activityType = activityType - self.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates - self.desiredAccuracy = desiredAccuracy - self.distanceFilter = distanceFilter - self.headingFilter = headingFilter - self.headingOrientation = headingOrientation +extension LocationManager { + public struct Properties: Equatable { + var activityType: CLActivityType? = nil + + var allowsBackgroundLocationUpdates: Bool? = nil + + var desiredAccuracy: CLLocationAccuracy? = nil + + var distanceFilter: CLLocationDistance? = nil + + var headingFilter: CLLocationDegrees? = nil + + var headingOrientation: CLDeviceOrientation? = nil + + var pausesLocationUpdatesAutomatically: Bool? = nil + + var showsBackgroundLocationIndicator: Bool? = nil + + public static func == (lhs: Self, rhs: Self) -> Bool { + var isEqual = true +#if os(iOS) || targetEnvironment(macCatalyst) || os(watchOS) + isEqual = + isEqual + && lhs.activityType == rhs.activityType + && lhs.allowsBackgroundLocationUpdates == rhs.allowsBackgroundLocationUpdates +#endif + isEqual = + isEqual + && lhs.desiredAccuracy == rhs.desiredAccuracy + && lhs.distanceFilter == rhs.distanceFilter +#if os(iOS) || targetEnvironment(macCatalyst) || os(watchOS) + isEqual = + isEqual + && lhs.headingFilter == rhs.headingFilter + && lhs.headingOrientation == rhs.headingOrientation +#endif +#if os(iOS) || targetEnvironment(macCatalyst) + isEqual = + isEqual + && lhs.pausesLocationUpdatesAutomatically == rhs.pausesLocationUpdatesAutomatically + && lhs.showsBackgroundLocationIndicator == rhs.showsBackgroundLocationIndicator +#endif + return isEqual + } + + @available(macOS, unavailable) + @available(tvOS, unavailable) + @available(watchOS, unavailable) + public init( + activityType: CLActivityType? = nil, + allowsBackgroundLocationUpdates: Bool? = nil, + desiredAccuracy: CLLocationAccuracy? = nil, + distanceFilter: CLLocationDistance? = nil, + headingFilter: CLLocationDegrees? = nil, + headingOrientation: CLDeviceOrientation? = nil, + pausesLocationUpdatesAutomatically: Bool? = nil, + showsBackgroundLocationIndicator: Bool? = nil + ) { + self.activityType = activityType + self.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates + self.desiredAccuracy = desiredAccuracy + self.distanceFilter = distanceFilter + self.headingFilter = headingFilter + self.headingOrientation = headingOrientation + self.pausesLocationUpdatesAutomatically = pausesLocationUpdatesAutomatically + self.showsBackgroundLocationIndicator = showsBackgroundLocationIndicator + } + + @available(iOS, unavailable) + @available(macCatalyst, unavailable) + @available(watchOS, unavailable) + public init( + desiredAccuracy: CLLocationAccuracy? = nil, + distanceFilter: CLLocationDistance? = nil + ) { + self.desiredAccuracy = desiredAccuracy + self.distanceFilter = distanceFilter + } + + @available(iOS, unavailable) + @available(macCatalyst, unavailable) + @available(macOS, unavailable) + @available(tvOS, unavailable) + public init( + activityType: CLActivityType? = nil, + allowsBackgroundLocationUpdates: Bool? = nil, + desiredAccuracy: CLLocationAccuracy? = nil, + distanceFilter: CLLocationDistance? = nil, + headingFilter: CLLocationDegrees? = nil, + headingOrientation: CLDeviceOrientation? = nil + ) { + self.activityType = activityType + self.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates + self.desiredAccuracy = desiredAccuracy + self.distanceFilter = distanceFilter + self.headingFilter = headingFilter + self.headingOrientation = headingOrientation + } } - } } diff --git a/Sources/ComposableCoreLocation/Live.swift b/Sources/ComposableCoreLocation/Live.swift index 5a6450d..d69f234 100644 --- a/Sources/ComposableCoreLocation/Live.swift +++ b/Sources/ComposableCoreLocation/Live.swift @@ -337,7 +337,7 @@ private final class LocationManagerDelegate: NSObject, CLLocationManagerDelegate send( .didRangeBeacons( beacons.map(Beacon.init(rawValue:)), - satisfyingConstraint: BeaconConstraint(rawValue: beaconConstraint) + satisfyingConstraint: beaconConstraint ) ) } @@ -350,7 +350,7 @@ private final class LocationManagerDelegate: NSObject, CLLocationManagerDelegate ) { send( .didFailRanging( - beaconConstraint: BeaconConstraint(rawValue: beaconConstraint), + beaconConstraint: beaconConstraint, error: LocationManager.Error(error)) ) }