Skip to content

Commit 62d38fb

Browse files
committed
Enable ExistentialAny
1 parent 46c747b commit 62d38fb

26 files changed

+93
-77
lines changed

Examples/Packages/CrossPlatform/Package.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import PackageDescription
44

55
let atoms = Target.Dependency.product(name: "Atoms", package: "swiftui-atom-properties")
6+
let swiftSettings: [SwiftSetting] = [
7+
.enableUpcomingFeature("ExistentialAny"),
8+
]
69

710
let package = Package(
811
name: "CrossPlatformExamples",
@@ -25,11 +28,12 @@ let package = Package(
2528
atoms,
2629
"ExampleCounter",
2730
"ExampleTodo",
28-
]
31+
],
32+
swiftSettings: swiftSettings
2933
),
30-
.target(name: "ExampleCounter", dependencies: [atoms]),
31-
.testTarget(name: "ExampleCounterTests", dependencies: ["ExampleCounter"]),
32-
.target(name: "ExampleTodo", dependencies: [atoms]),
33-
.testTarget(name: "ExampleTodoTests", dependencies: ["ExampleTodo"]),
34+
.target(name: "ExampleCounter", dependencies: [atoms], swiftSettings: swiftSettings),
35+
.testTarget(name: "ExampleCounterTests", dependencies: ["ExampleCounter"], swiftSettings: swiftSettings),
36+
.target(name: "ExampleTodo", dependencies: [atoms], swiftSettings: swiftSettings),
37+
.testTarget(name: "ExampleTodoTests", dependencies: ["ExampleTodo"], swiftSettings: swiftSettings),
3438
]
3539
)

Examples/Packages/iOS/Package.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import PackageDescription
44

55
let atoms = Target.Dependency.product(name: "Atoms", package: "swiftui-atom-properties")
6+
let swiftSettings: [SwiftSetting] = [
7+
.enableUpcomingFeature("ExistentialAny"),
8+
]
69

710
let package = Package(
811
name: "iOSExamples",
@@ -26,15 +29,16 @@ let package = Package(
2629
"ExampleMap",
2730
"ExampleVoiceMemo",
2831
"ExampleTimeTravel",
29-
]
32+
],
33+
swiftSettings: swiftSettings
3034
),
31-
.target(name: "ExampleMovieDB", dependencies: [atoms]),
32-
.testTarget(name: "ExampleMovieDBTests", dependencies: ["ExampleMovieDB"]),
33-
.target(name: "ExampleMap", dependencies: [atoms]),
34-
.testTarget(name: "ExampleMapTests", dependencies: ["ExampleMap"]),
35-
.target(name: "ExampleVoiceMemo", dependencies: [atoms]),
36-
.testTarget(name: "ExampleVoiceMemoTests", dependencies: ["ExampleVoiceMemo"]),
37-
.target(name: "ExampleTimeTravel", dependencies: [atoms]),
38-
.testTarget(name: "ExampleTimeTravelTests", dependencies: ["ExampleTimeTravel"]),
35+
.target(name: "ExampleMovieDB", dependencies: [atoms], swiftSettings: swiftSettings),
36+
.testTarget(name: "ExampleMovieDBTests", dependencies: ["ExampleMovieDB"], swiftSettings: swiftSettings),
37+
.target(name: "ExampleMap", dependencies: [atoms], swiftSettings: swiftSettings),
38+
.testTarget(name: "ExampleMapTests", dependencies: ["ExampleMap"], swiftSettings: swiftSettings),
39+
.target(name: "ExampleVoiceMemo", dependencies: [atoms], swiftSettings: swiftSettings),
40+
.testTarget(name: "ExampleVoiceMemoTests", dependencies: ["ExampleVoiceMemo"], swiftSettings: swiftSettings),
41+
.target(name: "ExampleTimeTravel", dependencies: [atoms], swiftSettings: swiftSettings),
42+
.testTarget(name: "ExampleTimeTravelTests", dependencies: ["ExampleTimeTravel"], swiftSettings: swiftSettings),
3943
]
4044
)

Examples/Packages/iOS/Sources/ExampleMap/Atoms.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import Atoms
22
import CoreLocation
33

44
final class LocationObserver: NSObject, ObservableObject, CLLocationManagerDelegate, @unchecked Sendable {
5-
let manager: LocationManagerProtocol
5+
let manager: any LocationManagerProtocol
66

77
deinit {
88
manager.stopUpdatingLocation()
99
}
1010

11-
init(manager: LocationManagerProtocol) {
11+
init(manager: any LocationManagerProtocol) {
1212
self.manager = manager
1313
super.init()
1414
manager.delegate = self
@@ -32,13 +32,13 @@ final class LocationObserver: NSObject, ObservableObject, CLLocationManagerDeleg
3232
}
3333
}
3434

35-
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
35+
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
3636
print(error.localizedDescription)
3737
}
3838
}
3939

4040
struct LocationManagerAtom: ValueAtom, Hashable {
41-
func value(context: Context) -> LocationManagerProtocol {
41+
func value(context: Context) -> any LocationManagerProtocol {
4242
let manager = CLLocationManager()
4343
manager.desiredAccuracy = kCLLocationAccuracyBest
4444
return manager

Examples/Packages/iOS/Sources/ExampleMap/Dependency/LocationManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CoreLocation
22

33
protocol LocationManagerProtocol: AnyObject {
4-
var delegate: CLLocationManagerDelegate? { get set }
4+
var delegate: (any CLLocationManagerDelegate)? { get set }
55
var desiredAccuracy: CLLocationAccuracy { get set }
66
var location: CLLocation? { get }
77
var authorizationStatus: CLAuthorizationStatus { get }
@@ -12,7 +12,7 @@ protocol LocationManagerProtocol: AnyObject {
1212
extension CLLocationManager: LocationManagerProtocol {}
1313

1414
final class MockLocationManager: LocationManagerProtocol, @unchecked Sendable {
15-
weak var delegate: CLLocationManagerDelegate?
15+
weak var delegate: (any CLLocationManagerDelegate)?
1616
var desiredAccuracy = kCLLocationAccuracyKilometer
1717
var location: CLLocation? = nil
1818
var authorizationStatus = CLAuthorizationStatus.notDetermined

Examples/Packages/iOS/Sources/ExampleMovieDB/Atoms/CommonAtoms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Atoms
22
import UIKit
33

44
struct APIClientAtom: ValueAtom, Hashable {
5-
func value(context: Context) -> APIClientProtocol {
5+
func value(context: Context) -> any APIClientProtocol {
66
APIClient()
77
}
88
}

Examples/Packages/iOS/Sources/ExampleMovieDB/Atoms/MoviesAtoms.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import Foundation
44
@MainActor
55
final class MovieLoader: ObservableObject {
66
@Published
7-
private(set) var pages = AsyncPhase<[PagedResponse<Movie>], Error>.suspending
8-
private let api: APIClientProtocol
7+
private(set) var pages = AsyncPhase<[PagedResponse<Movie>], any Error>.suspending
8+
private let api: any APIClientProtocol
99
let filter: Filter
1010

11-
init(api: APIClientProtocol, filter: Filter) {
11+
init(api: any APIClientProtocol, filter: Filter) {
1212
self.api = api
1313
self.filter = filter
1414
}

Examples/Packages/iOS/Sources/ExampleMovieDB/Backend/APIClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ private extension APIClient {
9595
}
9696

9797
final class MockAPIClient: APIClientProtocol, @unchecked Sendable {
98-
var imageResponse = Result<UIImage, Error>.failure(URLError(.unknown))
99-
var filteredMovieResponse = Result<PagedResponse<Movie>, Error>.failure(URLError(.unknown))
100-
var creditsResponse = Result<Credits, Error>.failure(URLError(.unknown))
101-
var searchMoviesResponse = Result<PagedResponse<Movie>, Error>.failure(URLError(.unknown))
98+
var imageResponse = Result<UIImage, any Error>.failure(URLError(.unknown))
99+
var filteredMovieResponse = Result<PagedResponse<Movie>, any Error>.failure(URLError(.unknown))
100+
var creditsResponse = Result<Credits, any Error>.failure(URLError(.unknown))
101+
var searchMoviesResponse = Result<PagedResponse<Movie>, any Error>.failure(URLError(.unknown))
102102

103103
func getImage(path: String, size: ImageSize) async throws -> UIImage {
104104
try imageResponse.get()

Examples/Packages/iOS/Sources/ExampleMovieDB/Entities/Failable.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
@propertyWrapper
2-
struct Failable<T: Decodable & Sendable>: Decodable & Sendable {
2+
struct Failable<T: Decodable & Sendable>: Decodable, Sendable {
33
var wrappedValue: T?
44

55
init(wrappedValue: T?) {
66
self.wrappedValue = wrappedValue
77
}
88

9-
init(from decoder: Decoder) throws {
9+
init(from decoder: any Decoder) throws {
1010
let container = try decoder.singleValueContainer()
1111
let wrappedValue = try? container.decode(T.self)
1212
self.init(wrappedValue: wrappedValue)
1313
}
1414
}
1515

1616
extension Failable: Encodable where T: Encodable {
17-
func encode(to encoder: Encoder) throws {
17+
func encode(to encoder: any Encoder) throws {
1818
var container = encoder.singleValueContainer()
1919
try container.encode(wrappedValue)
2020
}

Examples/Packages/iOS/Sources/ExampleMovieDB/Views/CastList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct CastList: View {
77
@ViewContext
88
var context
99

10-
var casts: AsyncPhase<[Credits.Person], Error> {
10+
var casts: AsyncPhase<[Credits.Person], any Error> {
1111
context.watch(CastsAtom(movieID: movieID).phase)
1212
}
1313

Examples/Packages/iOS/Sources/ExampleMovieDB/Views/NetworkImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct NetworkImage: View {
88
@ViewContext
99
var context
1010

11-
var image: Task<UIImage, Error> {
11+
var image: Task<UIImage, any Error> {
1212
context.watch(ImageAtom(path: path, size: size))
1313
}
1414

0 commit comments

Comments
 (0)