Skip to content

Commit 4ac98cf

Browse files
committed
DocC updates
- Document codable support and caveats - Use overloaded symbols
1 parent a541c5b commit 4ac98cf

File tree

14 files changed

+62
-91
lines changed

14 files changed

+62
-91
lines changed

.spi.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: 1
22
builder:
33
configs:
4-
- scheme: Sharing
5-
documentation_targets: [Sharing]
4+
- scheme: Sharing
5+
documentation_targets: [Sharing]
6+
custom_documentation_parameters:
7+
- '--enable-experimental-overloaded-symbol-presentation'

Sources/Sharing/Documentation.docc/Articles/DerivingSharedState.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ responsible for persisting and deriving shared state to pass to the child.
8282
### Optional shared state
8383

8484
If your shared state is optional, it is possible to unwrap it as a non-optional shared value via
85-
``Shared/init(_:)-2z7om``.
85+
``Shared/init(_:)``.
8686

8787
```swift
8888
@Shared var currentUser: User?
@@ -96,8 +96,8 @@ if let loggedInUser = Shared($currentUser) {
9696

9797
If your shared state is a collection, in particular an `IdentifiedArray`, then we have another tool
9898
for deriving shared state to a particular element of the array. You can pass the shared collection
99-
to a ``Swift/RangeReplaceableCollection``'s ``Swift/RangeReplaceableCollection/init(_:)-53j6s`` to
100-
create a collection of shared elements:
99+
to a ``Swift/RangeReplaceableCollection``'s ``Swift/RangeReplaceableCollection/init(_:)`` to create
100+
a collection of shared elements:
101101

102102
```swift
103103
@Shared(.fileStorage(.todos)) var todos: IdentifiedArrayOf<Todo> = []
@@ -108,8 +108,8 @@ ForEach(Array($todos)) { $todo in // '$todo' is a 'Shared<Todo>'
108108
```
109109

110110
You can also subscript into a ``Shared`` collection with the `IdentifiedArray[id:]` subscript. This
111-
will give a piece of shared optional state, which you can then unwrap with the
112-
``Shared/init(_:)-2z7om`` initializer:
111+
will give a piece of shared optional state, which you can then unwrap with the ``Shared/init(_:)``
112+
initializer:
113113

114114
```swift
115115
@Shared(.fileStorage(.todos)) var todos: IdentifiedArrayOf<Todo> = []
@@ -121,7 +121,7 @@ todo // Shared<Todo>
121121

122122
### Read-only shared state
123123

124-
Any `@Shared` value can be made read-only via ``SharedReader/init(_:)-9wqv4``:
124+
Any `@Shared` value can be made read-only via ``SharedReader/init(_:)``:
125125

126126
```swift
127127
// Parent feature needs read-write access to the option

Sources/Sharing/Documentation.docc/Articles/Gotchas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ appropriate thing.
3737
For example, if the data type is sharing state with a persistence strategy, you can _decode_ by
3838
delegating to the memberwise initializer that implicitly loads the shared value from the property
3939
wrapper's persistence strategy, or you can explicitly initialize a shared value via
40-
``Shared/init(wrappedValue:_:)-5xce4``. And you can _encode_ by skipping the shared value:
40+
``Shared/init(wrappedValue:_:)``. And you can _encode_ by skipping the shared value:
4141

4242
```swift
4343
struct TodosFeature {

Sources/Sharing/Documentation.docc/Articles/InitializationRules.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ following:
2222
### Persisted @Shared state
2323

2424
If you are using a persistence strategy with shared state (_e.g._
25-
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)-45ltk>), [`fileStorage`](<doc:SharedReaderKey/fileStorage(_:decoder:encoder:)>),
26-
_etc._), then the initializer should take a plain, non-`Shared` value and you will construct
27-
the `Shared` value in the initializer using ``Shared/init(wrappedValue:_:)-5xce4`` which takes a
28-
``SharedKey`` as the second argument:
25+
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)>),
26+
[`fileStorage`](<doc:SharedReaderKey/fileStorage(_:decoder:encoder:)>), _etc._), then the
27+
initializer should take a plain, non-`Shared` value and you will construct the `Shared` value in the
28+
initializer using ``Shared/init(wrappedValue:_:)`` which takes a ``SharedKey`` as the second
29+
argument:
2930

3031
```swift
3132
class FeatureModel {
@@ -45,9 +46,9 @@ argument because the persistence strategy is specified in the initializer.
4546

4647
> Important: The value passed to this initializer is only used if the external storage does not
4748
> already have a value. If a value exists in the storage then it is not used. In fact, the
48-
> `wrappedValue` argument of ``Shared/init(wrappedValue:_:)-5xce4`` is an `@autoclosure` so that it
49-
> is not even evaluated if not used. For that reason you may prefer to make the argument to the
50-
> initializer an `@autoclosure`, as well, so that it too is evaluated only if actually used:
49+
> `wrappedValue` argument of ``Shared/init(wrappedValue:_:)`` is an `@autoclosure` so that it is not
50+
> even evaluated if not used. For that reason you may prefer to make the argument to the initializer
51+
> an `@autoclosure`, as well, so that it too is evaluated only if actually used:
5152
>
5253
> ```swift
5354
> public struct State {

Sources/Sharing/Documentation.docc/Articles/PersistenceStrategies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ your own custom strategies.
77

88
When using `@Shared` you can supply an optional persistence strategy to represent that the state
99
you are holding onto is being shared with an external system. The library ships with 3 kinds of
10-
strategies: [`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)-45ltk>),
10+
strategies: [`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)>),
1111
[`fileStorage`](<doc:SharedReaderKey/fileStorage(_:decoder:encoder:)>), and
1212
[`inMemory`](<doc:SharedReaderKey/inMemory(_:)>). These strategies are defined as conformances to
1313
the ``SharedKey`` protocol, and it is possible for you to provide your own conformances for sharing
@@ -41,7 +41,7 @@ out of sync.
4141
### User defaults
4242

4343
If you would like to persist your shared value across application launches, then you can use the
44-
``SharedReaderKey/appStorage(_:store:)-45ltk`` strategy with `@Shared` in order to automatically
44+
``SharedReaderKey/appStorage(_:store:)`` strategy with `@Shared` in order to automatically
4545
persist any changes to the value to user defaults. It works similarly to in-memory sharing discussed
4646
above. It requires a key to store the value in user defaults, as well as a default value that will
4747
be used when there is no value in the user defaults:

Sources/Sharing/Documentation.docc/Articles/Testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trample over each other.
1313
Luckily the tools in this library were built with testing in mind, and you can usually test your
1414
features as if you were holding onto regular, non-shared state. For example, if you have a model
1515
that holds onto an integer that is stored in
16-
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)-45ltk>) like so:
16+
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)>) like so:
1717

1818
```swift
1919
@Observable
@@ -80,7 +80,7 @@ func increment() {
8080
### Testing when using custom persistence strategies
8181

8282
When creating your own custom persistence strategies you must be careful to do so in a style that
83-
is amenable to testing. For example, the ``SharedReaderKey/appStorage(_:store:)-45ltk`` persistence
83+
is amenable to testing. For example, the ``SharedReaderKey/appStorage(_:store:)`` persistence
8484
strategy that comes with the library uses a ``Dependencies/DependencyValues/defaultAppStorage``
8585
dependency so that one can inject a custom `UserDefaults` in order to execute in a controlled
8686
environment. When your app runs in the simulator or on device,

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A ``SharedKey`` conformance that persists simple pieces of data to user defaults, such as numbers,
44
strings, booleans and URLs. It can be used with ``Shared`` by providing the
5-
``SharedReaderKey/appStorage(_:store:)-45ltk`` value and specifying a default value:
5+
``SharedReaderKey/appStorage(_:store:)`` value and specifying a default value:
66

77
```swift
88
@Shared(.appStorage("isOn")) var isOn = true
@@ -24,7 +24,7 @@ func externalWrite() {
2424
}
2525
```
2626

27-
### Default app storage
27+
## Default app storage
2828

2929
When running your app in a simulator or device, `appStorage` will use the `standard` user defaults
3030
for persisting your state. If you want to use a different user defaults, you can invoke the
@@ -68,7 +68,7 @@ func basics() {
6868
}
6969
```
7070

71-
### Special characters in keys
71+
## Special characters in keys
7272

7373
The `appStorage` persistence strategy can change its behavior depending on the characters its key
7474
contains. If the key does not contain periods (".") or at-symbols ("@"), then `appStorage` can use
@@ -93,33 +93,22 @@ prepareDependencies {
9393
```
9494

9595
> Important: We highly recommend that you avoid using periods and at-symbols in your `appStorage`
96-
keys. Instead you can use other delimiting symbols, such as ":", "|", "/", etc.
96+
> keys. Instead you can use other delimiting symbols, such as ":", "|", "/", etc.
97+
98+
## Codable support
99+
100+
The `appStorage` persistence strategy provides support for `Codable` types even though `@AppStorage`
101+
omits it for unstated reasons. If you choose to use `appStorage` with a `Codable` type, proceed with
102+
caution and care. Avoid large, unbounded data types, like arrays and dictionaries, which may grow
103+
larger than user defaults allows. If you want to share and persist an array or dictionary across
104+
your application, prefer [`fileStorage`](<doc:SharedReaderKey/fileStorage(_:decoder:encoder:)>),
105+
instead.
97106

98107
## Topics
99108

100-
### Storing a value
101-
102-
- ``SharedReaderKey/appStorage(_:store:)-45ltk`` <!-- Bool -->
103-
- ``SharedReaderKey/appStorage(_:store:)-vqgl`` <!-- Data -->
104-
- ``SharedReaderKey/appStorage(_:store:)-3dtm`` <!-- Date -->
105-
- ``SharedReaderKey/appStorage(_:store:)-7dai0`` <!-- Double -->
106-
- ``SharedReaderKey/appStorage(_:store:)-c6ap`` <!-- Int -->
107-
- ``SharedReaderKey/appStorage(_:store:)-5663z`` <!-- String -->
108-
- ``SharedReaderKey/appStorage(_:store:)-6msr0`` <!-- URL -->
109-
- ``SharedReaderKey/appStorage(_:store:)-2tp0t`` <!-- RawRepresentable<Int> -->
110-
- ``SharedReaderKey/appStorage(_:store:)-95ztf`` <!-- RawRepresentable<String> -->
111-
112-
### Storing an optional value
113-
114-
- ``SharedReaderKey/appStorage(_:store:)-8ys3t`` <!-- Bool? -->
115-
- ``SharedReaderKey/appStorage(_:store:)-1vfr4`` <!-- Data? -->
116-
- ``SharedReaderKey/appStorage(_:store:)-8cy6a`` <!-- Date? -->
117-
- ``SharedReaderKey/appStorage(_:store:)-8f3hz`` <!-- Double? -->
118-
- ``SharedReaderKey/appStorage(_:store:)-8bf8y`` <!-- Int? -->
119-
- ``SharedReaderKey/appStorage(_:store:)-4la2p`` <!-- String? -->
120-
- ``SharedReaderKey/appStorage(_:store:)-7fd26`` <!-- URL? -->
121-
- ``SharedReaderKey/appStorage(_:store:)-2vfgj`` <!-- RawRepresentable<Int?> -->
122-
- ``SharedReaderKey/appStorage(_:store:)-2i17q`` <!-- RawRepresentable<String?> -->
109+
### Storing values
110+
111+
- ``SharedReaderKey/appStorage(_:store:)``
123112

124113
### Overriding app storage
125114

Sources/Sharing/Documentation.docc/Extensions/Shared.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Overview
44

55
Use shared state to allow for multiple parts of your application to hold onto the same piece of
6-
mutable data. For example, you can have two different obsevable models hold onto a collection of
6+
mutable data. For example, you can have two different observable models hold onto a collection of
77
data that is also synchronized to the file system:
88

99
```swift
@@ -34,11 +34,11 @@ also update to hold the freshest data.
3434

3535
The `@Shared` property wrapper gives you a succinct and consistent way to persist any kind of data
3636
in your application. The library comes with 3 strategies:
37-
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)-45ltk>),
37+
[`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)>),
3838
[`fileStorage`](<doc:SharedReaderKey/fileStorage(_:decoder:encoder:)>), and
3939
[`inMemory`](<doc:SharedReaderKey/inMemory(_:)>).
4040

41-
The [`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)-45ltk>) strategy is useful for store small
41+
The [`appStorage`](<doc:SharedReaderKey/appStorage(_:store:)>) strategy is useful for store small
4242
pieces of simple data in user defaults, such as settings:
4343

4444
```swift
@@ -109,7 +109,7 @@ See <doc:Testing> for more information on how to test your features when using `
109109

110110
### Creating a persisted value
111111

112-
- ``init(wrappedValue:_:)-5xce4``
112+
- ``init(wrappedValue:_:)``
113113

114114
### Creating a shared value
115115

@@ -118,9 +118,8 @@ See <doc:Testing> for more information on how to test your features when using `
118118

119119
### Transforming a shared value
120120

121-
- ``subscript(dynamicMember:)-68021``
122-
- ``subscript(dynamicMember:)-318vw``
123-
- ``init(_:)-2z7om``
121+
- ``subscript(dynamicMember:)``
122+
- ``init(_:)``
124123

125124
### Accessing the value
126125

Sources/Sharing/Documentation.docc/Extensions/SharedInit.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

Sources/Sharing/Documentation.docc/Extensions/SharedReader.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if remoteConfig.isToggleEnabled {
5757

5858
### Creating a persisted reader
5959

60-
- ``init(wrappedValue:_:)-56tir``
60+
- ``init(wrappedValue:_:)``
6161

6262
### Creating a shared reader
6363

@@ -66,10 +66,8 @@ if remoteConfig.isToggleEnabled {
6666

6767
### Transforming a shared value
6868

69-
- ``subscript(dynamicMember:)-3jfdr``
70-
- ``init(_:)-9wqv4``
71-
- ``init(_:)-9ka0y``
72-
- ``init(_:)-498ca``
69+
- ``subscript(dynamicMember:)``
70+
- ``init(_:)``
7371

7472
### Reading the value
7573

0 commit comments

Comments
 (0)