Skip to content

Commit 0ed067c

Browse files
authored
Swift 6.2 Back-port (#141)
* Bring in changes from Swift 6.2 * wip * wip * wip * wip * Remove macro compatibility check * Revert "Remove macro compatibility check" This reverts commit 6fa5ce7. * fix * wip * remove for now * wip * wip * wip * wip * rename * wip * wip
1 parent d817a57 commit 0ed067c

37 files changed

+2318
-1690
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
name: macOS
1919
strategy:
2020
matrix:
21-
xcode: ['15.4']
21+
xcode: ['16.4']
2222
config: ['debug', 'release']
23-
runs-on: macos-14
23+
runs-on: macos-15
2424
steps:
2525
- uses: actions/checkout@v4
2626
- name: Select Xcode ${{ matrix.xcode }}
@@ -61,15 +61,3 @@ jobs:
6161
6262
- name: Build
6363
run: swift build --swift-sdk wasm32-unknown-wasi -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
64-
65-
check-macro-compatibility:
66-
name: Check Macro Compatibility
67-
runs-on: macos-latest
68-
steps:
69-
- name: Checkout repository
70-
uses: actions/checkout@v4
71-
- name: Run Swift Macro Compatibility Check
72-
uses: Matejkob/swift-macro-compatibility-check@v1
73-
with:
74-
run-tests: false
75-
major-versions-only: true

Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 35 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PLATFORM_IOS = iOS Simulator,id=$(call udid_for,iOS 17.2,iPhone \d\+ Pro [^M])
1+
PLATFORM_IOS = iOS Simulator,id=$(call udid_for,iOS 18.5,iPhone \d\+ Pro [^M])
22

33
test-compatibility:
44
xcodebuild \

Package.resolved

Lines changed: 35 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22

33
import CompilerPluginSupport
44
import PackageDescription
@@ -12,13 +12,19 @@ let package = Package(
1212
.watchOS(.v6),
1313
],
1414
products: [
15-
.library(name: "Perception", targets: ["Perception"]),
16-
.library(name: "PerceptionCore", targets: ["PerceptionCore"]),
15+
.library(
16+
name: "PerceptionCore",
17+
targets: ["PerceptionCore"]
18+
),
19+
.library(
20+
name: "Perception",
21+
targets: ["Perception"]
22+
),
1723
],
1824
dependencies: [
19-
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.1.0"),
25+
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.6.0"),
26+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.6.0"),
2027
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"602.0.0"),
21-
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
2228
],
2329
targets: [
2430
.target(
@@ -34,31 +40,31 @@ let package = Package(
3440
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
3541
]
3642
),
37-
.testTarget(
38-
name: "PerceptionTests",
39-
dependencies: ["Perception"]
40-
),
41-
4243
.macro(
4344
name: "PerceptionMacros",
4445
dependencies: [
4546
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
4647
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
4748
]
4849
),
50+
.testTarget(
51+
name: "PerceptionTests",
52+
dependencies: ["Perception"]
53+
),
4954
.testTarget(
5055
name: "PerceptionMacrosTests",
5156
dependencies: [
5257
"PerceptionMacros",
5358
.product(name: "MacroTesting", package: "swift-macro-testing"),
5459
]
5560
),
56-
]
61+
],
62+
swiftLanguageModes: [.v5]
5763
)
5864

59-
for target in package.targets where target.type != .system {
60-
target.swiftSettings = target.swiftSettings ?? []
61-
target.swiftSettings?.append(contentsOf: [
62-
.enableExperimentalFeature("StrictConcurrency"),
63-
])
64-
}
65+
#if !os(Windows)
66+
// Add the documentation compiler plugin if possible
67+
package.dependencies.append(
68+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
69+
)
70+
#endif

README.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fswift-perception%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/pointfreeco/swift-perception)
66
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fswift-perception%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/pointfreeco/swift-perception)
77

8-
Observation tools for platforms that do not officially support observation.
8+
Swift's Observation tools, back-ported to more platforms.
99

1010
## Learn More
1111

@@ -18,11 +18,11 @@ host the [Point-Free][pointfreeco] video series which explores advanced Swift la
1818

1919
## Overview
2020

21-
The Perception library provides tools that mimic `@Observable` and `withObservationTracking` in
22-
Swift 5.9, but they are backported to work all the way back to iOS 13, macOS 10.15, tvOS 13 and
23-
watchOS 6. This means you can start taking advantage of Swift 5.9's observation tools today,
24-
even if you can't drop support for older Apple platforms. Using this library's tools works almost
25-
exactly as using the official tools, but with one small exception.
21+
The Perception library back-ports `@Observable`, `withObservationTracking`, and `Observations` all
22+
the way back to iOS 13, macOS 10.15, tvOS 13 and watchOS 6. This means you can take advantage of
23+
all of Swift's observation tools today, even if you can't drop support for older Apple platforms.
24+
Using this library's tools works almost exactly as using the official tools, with one small
25+
exception.
2626

2727
To begin, mark a class as being observable by using the `@Perceptible` macro instead of the
2828
`@Observable` macro:
@@ -54,26 +54,33 @@ struct FeatureView: View {
5454
var body: some View {
5555
WithPerceptionTracking {
5656
Form {
57-
Text(model.count.description)
57+
Text("\(model.count)")
5858
Button("Increment") { model.count += 1 }
5959
}
6060
}
6161
}
6262
}
6363
```
6464

65-
It's unfortunate to have to wrap your view's content in `WithPerceptionTracking`, however if you
66-
forget then you will helpfully get a runtime warning letting you know that observation is not
67-
set up correctly:
65+
It's unfortunate to have to wrap your view's content in `WithPerceptionTracking`, but if you forget
66+
then you will helpfully get a runtime warning letting you know that observation is not set up
67+
correctly:
6868

69-
> 🟣 Runtime Warning: Perceptible state was accessed but is not being tracked. Track changes
70-
> to state by wrapping your view in a 'WithPerceptionTracking' view. This must also be done
71-
> for any escaping, trailing closures, such as 'GeometryReader', `LazyVStack` (and all lazy
72-
> views), navigation APIs ('sheet', 'popover', 'fullScreenCover', etc.), and others.
69+
> 🟣 Runtime Warning: Perceptible state was accessed from a view but is not being tracked.
70+
71+
Finally, the `Observations` async sequence has been back-ported as `Perceptions`, which can be used
72+
to observe changes to perceptible and observable objects over time:
73+
74+
```swift
75+
let counts = Perceptions { model.count }
76+
for await count in counts {
77+
print("Count changed: \(count)")
78+
}
79+
```
7380

7481
### Bindable
7582

76-
SwiftUI's `@Bindable` property wrapper has also been backported to support perceptible objects. You
83+
SwiftUI's `@Bindable` property wrapper has also been back-ported to support perceptible objects. You
7784
can simply qualify the property wrapper with the `Perception` module:
7885

7986
```swift
@@ -87,7 +94,7 @@ struct FeatureView: View {
8794
### Environment
8895

8996
SwiftUI's `@Environment` property wrapper and `environment` view modifier's support for observation
90-
has also been backported to support perceptible objects using the exact same APIs:
97+
has also been back-ported to support perceptible objects using the exact same APIs:
9198

9299
```swift
93100
struct FeatureView: View {
@@ -102,13 +109,14 @@ struct FeatureView: View {
102109

103110
## Community
104111

105-
If you want to discuss this library or have a question about how to use it to solve
106-
a particular problem, there are a number of places you can discuss with fellow
112+
If you want to discuss this library or have a question about how to use it to solve a particular
113+
problem, there are a number of places you can discuss with fellow
107114
[Point-Free](https://www.pointfree.co) enthusiasts:
108115

109-
* For long-form discussions, we recommend the
110-
[discussions](https://github.com/pointfreeco/swift-perception/discussions) tab of this repo.
111-
* For casual chat, we recommend the [Point-Free Community Slack](https://pointfree.co/slack-invite).
116+
* For long-form discussions, we recommend the
117+
[discussions](https://github.com/pointfreeco/swift-perception/discussions) tab of this repo.
118+
* For casual chat, we recommend the
119+
[Point-Free Community Slack](https://pointfree.co/slack-invite).
112120

113121
## Documentation
114122

@@ -119,6 +127,6 @@ The latest documentation for the Perception APIs is available [here][docs].
119127
This library is released under the MIT license. See [LICENSE](LICENSE) for details.
120128

121129
[pointfreeco]: https://www.pointfree.co
122-
[mbrandonw]: https://twitter.com/mbrandonw
123-
[stephencelis]: https://twitter.com/stephencelis
130+
[mbrandonw]: https://x.com/mbrandonw
131+
[stephencelis]: https://x.com/stephencelis
124132
[docs]: https://swiftpackageindex.com/pointfreeco/swift-perception/main/documentation/perception
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ``Perception``
2+
3+
Swift's Observation tools, back-ported to more platforms.
4+
5+
## Overview
6+
7+
The core functionality of this library is defined in
8+
[`PerceptionCore`](<doc:/PerceptionCore>), which this module automatically exports.
9+
10+
This module also contains all of the macros that support the core functionality of the library.
11+
12+
See [`PerceptionCore`](<doc:/PerceptionCore>) for general library usage.
13+
14+
## Topics
15+
16+
### Perceptible conformance
17+
18+
- ``Perceptible()``
19+
20+
### Macros
21+
22+
- ``PerceptionTracked()``
23+
- ``PerceptionIgnored()``

0 commit comments

Comments
 (0)