Skip to content

Commit e11ca0e

Browse files
Require Swift 5.6 (#1491)
* Restore Swift 5.5 compatibility As pointed out in #1489, we somehow lost compatibility with Swift 5.5 (Xcode 13.2). While we hope to drop support when we hit 1.0, let's try to keep compatiblity in the meantime. * Update DependencyValues.swift * Update Sources/Dependencies/DependencyValues.swift Co-authored-by: Brandon Williams <[email protected]> * Require Swift 5.6 * Update ci.yml Co-authored-by: Brandon Williams <[email protected]>
1 parent d43ac98 commit e11ca0e

File tree

10 files changed

+232
-254
lines changed

10 files changed

+232
-254
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
runs-on: macos-12
2020
strategy:
2121
matrix:
22-
xcode: ['13.4.1', '14.0']
22+
xcode: ['13.4.1', '14.0.1']
2323
config: ['debug', 'release']
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v3
2626
- name: Select Xcode ${{ matrix.xcode }}
2727
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
2828
- name: Run ${{ matrix.config }} tests
@@ -32,9 +32,9 @@ jobs:
3232
runs-on: macos-12
3333
strategy:
3434
matrix:
35-
xcode: ['13.4.1', '14.0']
35+
xcode: ['13.4.1', '14.0.1']
3636
steps:
37-
- uses: actions/checkout@v2
37+
- uses: actions/checkout@v3
3838
- name: Select Xcode ${{ matrix.xcode }}
3939
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
4040
- name: Build for library evolution
@@ -43,17 +43,17 @@ jobs:
4343
benchmarks:
4444
runs-on: macos-12
4545
steps:
46-
- uses: actions/checkout@v2
46+
- uses: actions/checkout@v3
4747
- name: Select Xcode ${{ matrix.xcode }}
48-
run: sudo xcode-select -s /Applications/Xcode_14.0.app
48+
run: sudo xcode-select -s /Applications/Xcode_14.0.1.app
4949
- name: Run benchmark
5050
run: make benchmark
5151

5252
examples:
5353
runs-on: macos-12
5454
steps:
55-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v3
5656
- name: Select Xcode ${{ matrix.xcode }}
57-
run: sudo xcode-select -s /Applications/Xcode_14.0.app
57+
run: sudo xcode-select -s /Applications/Xcode_14.0.1.app
5858
- name: Run tests
5959
run: make test-examples

Examples/CaseStudies/tvOSCaseStudies/FocusView.swift

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,56 @@ struct Focus: ReducerProtocol {
3232
}
3333
}
3434

35-
#if swift(>=5.3)
36-
@available(tvOS 14.0, *)
37-
struct FocusView: View {
38-
let store: StoreOf<Focus>
35+
@available(tvOS 14.0, *)
36+
struct FocusView: View {
37+
let store: StoreOf<Focus>
3938

40-
@Environment(\.resetFocus) var resetFocus
41-
@Namespace private var namespace
39+
@Environment(\.resetFocus) var resetFocus
40+
@Namespace private var namespace
4241

43-
var body: some View {
44-
WithViewStore(self.store, observe: { $0 }) { viewStore in
45-
VStack(spacing: 100) {
46-
Text(readMe)
47-
.font(.headline)
48-
.multilineTextAlignment(.leading)
49-
.padding()
42+
var body: some View {
43+
WithViewStore(self.store, observe: { $0 }) { viewStore in
44+
VStack(spacing: 100) {
45+
Text(readMe)
46+
.font(.headline)
47+
.multilineTextAlignment(.leading)
48+
.padding()
5049

51-
HStack(spacing: 40) {
52-
ForEach(1..<6) { index in
53-
Button(numbers[index]) {}
54-
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
55-
}
50+
HStack(spacing: 40) {
51+
ForEach(1..<6) { index in
52+
Button(numbers[index]) {}
53+
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
5654
}
57-
HStack(spacing: 40) {
58-
ForEach(6..<11) { index in
59-
Button(numbers[index]) {}
60-
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
61-
}
62-
}
63-
64-
Button("Focus Random") { viewStore.send(.randomButtonClicked) }
6555
}
66-
.onChange(of: viewStore.currentFocus) { _ in
67-
// Update the view's focus when the state tells us the focus changed.
68-
self.resetFocus(in: self.namespace)
56+
HStack(spacing: 40) {
57+
ForEach(6..<11) { index in
58+
Button(numbers[index]) {}
59+
.prefersDefaultFocus(viewStore.currentFocus == index, in: self.namespace)
60+
}
6961
}
70-
.focusScope(self.namespace)
62+
63+
Button("Focus Random") { viewStore.send(.randomButtonClicked) }
7164
}
65+
.onChange(of: viewStore.currentFocus) { _ in
66+
// Update the view's focus when the state tells us the focus changed.
67+
self.resetFocus(in: self.namespace)
68+
}
69+
.focusScope(self.namespace)
7270
}
7371
}
72+
}
7473

75-
@available(tvOS 14.0, *)
76-
struct FocusView_Previews: PreviewProvider {
77-
static var previews: some View {
78-
FocusView(
79-
store: Store(
80-
initialState: Focus.State(),
81-
reducer: Focus()
82-
)
74+
@available(tvOS 14.0, *)
75+
struct FocusView_Previews: PreviewProvider {
76+
static var previews: some View {
77+
FocusView(
78+
store: Store(
79+
initialState: Focus.State(),
80+
reducer: Focus()
8381
)
84-
}
82+
)
8583
}
86-
#endif
84+
}
8785

8886
private let numbers = [
8987
"Zero",

Examples/CaseStudies/tvOSCaseStudies/RootView.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ struct RootView: View {
1616

1717
var focusView: AnyView? {
1818
if #available(tvOS 14.0, *) {
19-
#if swift(>=5.3)
20-
return AnyView(
21-
NavigationLink(
22-
"Focus",
23-
destination: FocusView(
24-
store: self.store.scope(state: \.focus, action: Root.Action.focus)
25-
)
19+
return AnyView(
20+
NavigationLink(
21+
"Focus",
22+
destination: FocusView(
23+
store: self.store.scope(state: \.focus, action: Root.Action.focus)
2624
)
2725
)
28-
#else
29-
return nil
30-
#endif
26+
)
3127
} else {
3228
return nil
3329
}

Package.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.6
22

33
import PackageDescription
44

@@ -21,7 +21,8 @@ let package = Package(
2121
),
2222
],
2323
dependencies: [
24-
.package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
24+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
25+
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
2526
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.7.4"),
2627
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.8.0"),
2728
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.3.0"),
@@ -64,7 +65,7 @@ let package = Package(
6465
name: "swift-composable-architecture-benchmark",
6566
dependencies: [
6667
"ComposableArchitecture",
67-
.product(name: "Benchmark", package: "Benchmark"),
68+
.product(name: "Benchmark", package: "swift-benchmark"),
6869
]
6970
),
7071
]
@@ -80,10 +81,3 @@ let package = Package(
8081
// ])
8182
// )
8283
//}
83-
84-
#if swift(>=5.6)
85-
// Add the documentation compiler plugin if possible
86-
package.dependencies.append(
87-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
88-
)
89-
#endif
Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
import Foundation
22
import XCTestDynamicOverlay
33

4-
#if swift(>=5.6)
5-
extension DependencyValues {
6-
/// The current calendar that features should use when handling dates.
7-
///
8-
/// By default, the calendar returned from `Calendar.autoupdatingCurrent` is supplied. When used
9-
/// in a testing context, access will call to `XCTFail` when invoked, unless explicitly
10-
/// overridden using ``withValue(_:_:operation:)-705n``:
11-
///
12-
/// ```swift
13-
/// DependencyValues.withValue(\.calendar, Calendar(identifier: .gregorian)) {
14-
/// // Assertions...
15-
/// }
16-
/// ```
17-
///
18-
/// Or, if you are using the Composable Architecture, you can override dependencies directly
19-
/// on the `TestStore`:
20-
///
21-
/// ```swift
22-
/// let store = TestStore(
23-
/// initialState: MyFeature.State()
24-
/// reducer: MyFeature()
25-
/// )
26-
///
27-
/// store.dependencies.calendar = Calendar(identifier: .gregorian)
28-
/// ```
29-
public var calendar: Calendar {
30-
get { self[CalendarKey.self] }
31-
set { self[CalendarKey.self] = newValue }
32-
}
4+
extension DependencyValues {
5+
/// The current calendar that features should use when handling dates.
6+
///
7+
/// By default, the calendar returned from `Calendar.autoupdatingCurrent` is supplied. When used
8+
/// in a testing context, access will call to `XCTFail` when invoked, unless explicitly
9+
/// overridden using ``withValue(_:_:operation:)-705n``:
10+
///
11+
/// ```swift
12+
/// DependencyValues.withValue(\.calendar, Calendar(identifier: .gregorian)) {
13+
/// // Assertions...
14+
/// }
15+
/// ```
16+
///
17+
/// Or, if you are using the Composable Architecture, you can override dependencies directly
18+
/// on the `TestStore`:
19+
///
20+
/// ```swift
21+
/// let store = TestStore(
22+
/// initialState: MyFeature.State()
23+
/// reducer: MyFeature()
24+
/// )
25+
///
26+
/// store.dependencies.calendar = Calendar(identifier: .gregorian)
27+
/// ```
28+
public var calendar: Calendar {
29+
get { self[CalendarKey.self] }
30+
set { self[CalendarKey.self] = newValue }
31+
}
3332

34-
private enum CalendarKey: DependencyKey {
35-
static let liveValue = Calendar.autoupdatingCurrent
36-
static var testValue: Calendar {
37-
XCTFail(#"Unimplemented: @Dependency(\.calendar)"#)
38-
return .autoupdatingCurrent
39-
}
33+
private enum CalendarKey: DependencyKey {
34+
static let liveValue = Calendar.autoupdatingCurrent
35+
static var testValue: Calendar {
36+
XCTFail(#"Unimplemented: @Dependency(\.calendar)"#)
37+
return .autoupdatingCurrent
4038
}
4139
}
42-
#endif
40+
}

0 commit comments

Comments
 (0)