Skip to content

Commit 69011b6

Browse files
Add migration guide for 1.16. (#3491)
* Add migration guide for 1.16. * Update README.md --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent 333bc82 commit 69011b6

36 files changed

+295
-69
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,14 @@ advanced usages.
532532
The documentation for releases and `main` are available here:
533533

534534
* [`main`](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/)
535-
* [1.15.0](https://pointfreeco.github.io/swift-composable-architecture/1.15.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.15))
535+
* [1.16.0](https://pointfreeco.github.io/swift-composable-architecture/1.16.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.16))
536536

537537
<details>
538538
<summary>
539539
Other versions
540540
</summary>
541541

542+
* [1.15.0](https://pointfreeco.github.io/swift-composable-architecture/1.15.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.15))
542543
* [1.14.0](https://pointfreeco.github.io/swift-composable-architecture/1.14.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.14))
543544
* [1.13.0](https://pointfreeco.github.io/swift-composable-architecture/1.13.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.13))
544545
* [1.12.0](https://pointfreeco.github.io/swift-composable-architecture/1.12.0/documentation/composablearchitecture/) ([migration guide](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/migratingto1.12))

Sources/ComposableArchitecture/Documentation.docc/Articles/MigrationGuides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ APIs, and these guides contain tips to do so.
1414
1515
## Topics
1616

17+
- <doc:MigratingTo1.16>
1718
- <doc:MigratingTo1.15>
1819
- <doc:MigratingTo1.14>
1920
- <doc:MigratingTo1.13>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Migrating to 1.16
2+
3+
The `.appStorage` strategy used with `@Shared` now uses key-value observing instead of
4+
`NotificationCenter` when possible. Learn how this may affect your code.
5+
6+
## Overview
7+
8+
There are no steps needed to migrate to 1.16 of the Composable Architecture, but there has been
9+
a change to the underlying behavior of `.appStorage` that one should be aware of. When using
10+
`.appStorage` with `@Shared`, if your key does not contain the characters "." or "@", then changes
11+
to that key in `UserDefaults` will be observed using key-value observing (KVO).
12+
Otherwise, `NotificationCenter` will be used to observe changes.
13+
14+
KVO is a far more efficient way of observing changes to `UserDefaults` and it works cross-process,
15+
such as from widgets and app extensions. However, KVO does not work when the keys contain "."
16+
or "@", and so in those cases we must use the cruder tool of `NotificationCenter`. That is not
17+
as efficient, and it forces us to perform a thread-hop when the notification is posted before
18+
we can update the `@Shared` value. For this reason it is not possible to animate changes that are
19+
made directly to `UserDefaults`:
20+
21+
```swift
22+
withAnimation {
23+
// ⚠️ This will not animate any SwiftUI views using '@Shared(.appStorage("co.pointfree.count"))'
24+
UserDefaults.standard.set(0, forKey: "co.pointfree.count")
25+
}
26+
```
27+
28+
In general, we recommend using other delimeters for your keys, such as "/", ":", "-", etc.:
29+
30+
```swift
31+
@Shared(.appStorage("co:pointfree:count")) var count = 0
32+
```

Sources/ComposableArchitecture/Documentation.docc/Articles/MigrationGuides/MigratingTo1.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ enum Action {
279279
```
280280

281281
And in the reducer, instead of invoking
282-
``Reducer/forEach(_:action:element:fileID:filePath:line:column:)-3dw7i`` with a case path using the
282+
``Reducer/forEach(_:action:element:fileID:filePath:line:column:)-6zye8`` with a case path using the
283283
`/` prefix operator:
284284

285285
```swift

Sources/ComposableArchitecture/Documentation.docc/Articles/MigrationGuides/MigratingTo1.7.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ func viewDidLoad() {
904904
}
905905
```
906906

907-
This can now be done more simply using the ``ObjectiveC/NSObject/observe(_:)`` method defined on
907+
This can now be done more simply using the ``ObjectiveC/NSObject/observe(_:)-94oxy`` method defined on
908908
all `NSObject`s:
909909

910910
```swift
@@ -920,7 +920,7 @@ func viewDidLoad() {
920920
}
921921
```
922922

923-
Be sure to read the documentation for ``ObjectiveC/NSObject/observe(_:)`` to learn how to best
923+
Be sure to read the documentation for ``ObjectiveC/NSObject/observe(_:)-94oxy`` to learn how to best
924924
wield this tool.
925925

926926
### Replacing Store.ifLet
@@ -940,7 +940,7 @@ store
940940
```
941941

942942
This can now be done more simply using the `observe` method and
943-
``Store/scope(state:action:fileID:filePath:line:column:)-2ck1n``:
943+
``Store/scope(state:action:fileID:filePath:line:column:)-3yvuf``:
944944

945945
```swift
946946
observe {

Sources/ComposableArchitecture/Documentation.docc/Articles/SharingState.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ should take a plain, non-`Shared` value and you construct the `Shared` value in
318318
* You are using a persistence strategy with shared state (_e.g._
319319
``PersistenceReaderKey/appStorage(_:)-4l5b``, ``PersistenceReaderKey/fileStorage(_:decoder:encoder:)``, _etc._),
320320
then the initializer should take a plain, non-`Shared` value and you construct the `Shared` value in
321-
the initializer using ``Shared/init(wrappedValue:_:fileID:line:)-512rh`` which takes a
321+
the initializer using ``Shared/init(wrappedValue:_:fileID:line:)-9kfmy`` which takes a
322322
``PersistenceKey`` as the second argument:
323323

324324
```swift
@@ -338,7 +338,7 @@ the initializer using ``Shared/init(wrappedValue:_:fileID:line:)-512rh`` which t
338338

339339
> Important: The value passed to this initializer is only used if the external storage does not
340340
> already have a value. If a value exists in the storage then it is not used. In fact, the
341-
> `wrappedValue` argument of ``Shared/init(wrappedValue:_:fileID:line:)-512rh`` is an
341+
> `wrappedValue` argument of ``Shared/init(wrappedValue:_:fileID:line:)-9kfmy`` is an
342342
> `@autoclosure` so that it is not even evaluated if not used. For that reason you
343343
> may prefer to make the argument to the initializer an `@autoclosure` so that it too is evaluated
344344
> only if actually used:
@@ -436,7 +436,7 @@ responsible for persisting and deriving shared state to pass to the child.
436436
If your shared state is a collection, and in particular an `IdentifiedArray`, then we have another
437437
tool for deriving shared state to a particular element of the array. You can subscript into a
438438
``Shared`` collection with the `[id:]` subscript, and that will give a piece of optional shared
439-
state (thanks to a dynamic member overload ``Shared/subscript(dynamicMember:)-7ibhr``), which you
439+
state (thanks to a dynamic member overload ``Shared/subscript(dynamicMember:)-9xw64``), which you
440440
can then unwrap to turn into honest shared state:
441441

442442
```swift
@@ -1071,7 +1071,7 @@ own implementations of `encode(to:)` and `init(from:)` that do the appropriate t
10711071
For example, if the data type is sharing state with a persistence strategy, you can decode by
10721072
delegating to the memberwise initializer that implicitly loads the shared value from the property
10731073
wrapper's persistence strategy, or you can explicitly initialize a shared value via
1074-
``Shared/init(wrappedValue:_:fileID:line:)-512rh``. And for encoding you can often skip encoding
1074+
``Shared/init(wrappedValue:_:fileID:line:)-9kfmy``. And for encoding you can often skip encoding
10751075
the shared value:
10761076

10771077
```swift

Sources/ComposableArchitecture/Documentation.docc/Extensions/AppStorageKey.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
### Storing a value
66

7-
- ``PersistenceReaderKey/appStorage(_:)-4l5b``
8-
- ``PersistenceReaderKey/appStorage(_:)-6d47p``
9-
- ``PersistenceReaderKey/appStorage(_:)-6tsph``
10-
- ``PersistenceReaderKey/appStorage(_:)-69h4r``
11-
- ``PersistenceReaderKey/appStorage(_:)-xphy``
12-
- ``PersistenceReaderKey/appStorage(_:)-617ld``
13-
- ``PersistenceReaderKey/appStorage(_:)-6lnxu``
14-
- ``PersistenceReaderKey/appStorage(_:)-ibg0``
7+
- ``PersistenceReaderKey/appStorage(_:)-4l5b`` <!-- Bool -->
8+
- ``PersistenceReaderKey/appStorage(_:)-6d47p`` <!-- Data -->
9+
- ``PersistenceReaderKey/appStorage(_:)-6tsph`` <!-- Double -->
10+
- ``PersistenceReaderKey/appStorage(_:)-69h4r`` <!-- Integer -->
11+
- ``PersistenceReaderKey/appStorage(_:)-xphy`` <!-- String -->
12+
- ``PersistenceReaderKey/appStorage(_:)-617ld`` <!-- URL -->
13+
- ``PersistenceReaderKey/appStorage(_:)-6k27r`` <!-- RawRepresentable<Int> -->
14+
- ``PersistenceReaderKey/appStorage(_:)-m54v`` <!-- RawRepresentable<String> -->
1515

1616
### Storing an optional value
1717

18-
- ``PersistenceReaderKey/appStorage(_:)-4s3s5``
19-
- ``PersistenceReaderKey/appStorage(_:)-2dfnh``
20-
- ``PersistenceReaderKey/appStorage(_:)-5wv8g``
21-
- ``PersistenceReaderKey/appStorage(_:)-40e42``
22-
- ``PersistenceReaderKey/appStorage(_:)-4veqp``
23-
- ``PersistenceReaderKey/appStorage(_:)-7rox5``
24-
- ``PersistenceReaderKey/appStorage(_:)-2keyn``
25-
- ``PersistenceReaderKey/appStorage(_:)-7u49u``
18+
- ``PersistenceReaderKey/appStorage(_:)-4s3s5`` <!-- Bool -->
19+
- ``PersistenceReaderKey/appStorage(_:)-2dfnh`` <!-- Data -->
20+
- ``PersistenceReaderKey/appStorage(_:)-5wv8g`` <!-- Double -->
21+
- ``PersistenceReaderKey/appStorage(_:)-40e42`` <!-- Integer -->
22+
- ``PersistenceReaderKey/appStorage(_:)-4veqp`` <!-- String -->
23+
- ``PersistenceReaderKey/appStorage(_:)-7rox5`` <!-- URL -->
24+
- ``PersistenceReaderKey/appStorage(_:)-2cfq9`` <!-- RawRepresentable<Int> -->
25+
- ``PersistenceReaderKey/appStorage(_:)-9j150`` <!-- RawRepresentable<String> -->
2626

2727
### Key-path access
2828

29-
- ``PersistenceReaderKey/appStorage(_:)-5jsie``
29+
- ``PersistenceReaderKey/appStorage(_:)-69h4r``
3030
- ``AppStorageKeyPathKey``
3131

3232
### Overriding app storage

Sources/ComposableArchitecture/Documentation.docc/Extensions/Deprecations/ReducerDeprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ instead.
1515
- ``Reducer/ifLet(_:action:destination:fileID:filePath:line:column:)-5y8z4``
1616
- ``Reducer/ifLet(_:action:fileID:filePath:line:column:)-12kry``
1717
- ``Reducer/ifCaseLet(_:action:then:fileID:filePath:line:column:)-403y9``
18-
- ``Reducer/forEach(_:action:element:fileID:filePath:line:column:)-1oguc``
18+
- ``Reducer/forEach(_:action:element:fileID:filePath:line:column:)-o1gn``
1919
- ``Reducer/forEach(_:action:destination:fileID:filePath:line:column:)-74erx``
2020
- ``Reducer/onChange(of:removeDuplicates:_:)``
2121

Sources/ComposableArchitecture/Documentation.docc/Extensions/Reducer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ xcodebuild -skipMacroValidation …
581581
- ``Scope``
582582
- ``ifLet(_:action:then:fileID:filePath:line:column:)-2r2pn``
583583
- ``ifCaseLet(_:action:then:fileID:filePath:line:column:)-7sg8d``
584-
- ``forEach(_:action:element:fileID:filePath:line:column:)-3dw7i``
584+
- ``forEach(_:action:element:fileID:filePath:line:column:)-6zye8``
585585
- <doc:Navigation>
586586

587587
### Sharing state

Sources/ComposableArchitecture/Documentation.docc/Extensions/ReducerForEach.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ``ComposableArchitecture/Reducer/forEach(_:action:element:fileID:filePath:line:column:)-3dw7i``
1+
# ``ComposableArchitecture/Reducer/forEach(_:action:element:fileID:filePath:line:column:)-6zye8``
22

33
## Topics
44

0 commit comments

Comments
 (0)