Skip to content

Commit

Permalink
[5.0.0] release prep
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Jan 11, 2024
1 parent 01dc39b commit f5d6633
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Foil.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Foil'
s.version = '4.0.1'
s.version = '5.0.0'
s.license = 'MIT'

s.summary = 'A lightweight property wrapper for UserDefaults'
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ Foil, as in "let me quickly and easily **wrap** and **store** this leftover food
## Usage

You can use `@WrappedDefault` for non-optional values and `@WrappedDefaultOptional` for optional ones.
You can use `@FoilDefaultStorage` for non-optional values and `@FoilDefaultStorageOptional` for optional ones.
You may wish to store all your user defaults in one place, however, that is not necessary. **Any** property on **any type** can use this wrapper.

```swift
final class AppSettings {
static let shared = AppSettings()

@WrappedDefault(key: "flagEnabled")
@FoilDefaultStorage(key: "flagEnabled")
var flagEnabled = true

@WrappedDefault(key: "totalCount")
@FoilDefaultStorage(key: "totalCount")
var totalCount = 0

@WrappedDefaultOptional(key: "timestamp")
@FoilDefaultStorageOptional(key: "timestamp")
var timestamp: Date?
}

Expand All @@ -56,13 +56,13 @@ enum AppSettingsKey: String, CaseIterable {
case timestamp
}

extension WrappedDefault {
extension FoilDefaultStorage {
init(wrappedValue: T, _ key: AppSettingsKey) {
self.init(wrappedValue: wrappedValue, key: key.rawValue)
}
}

extension WrappedDefaultOptional {
extension FoilDefaultStorageOptional {
init(_ key: AppSettingsKey) {
self.init(key: key.rawValue)
}
Expand All @@ -77,10 +77,10 @@ There are [many ways to observe property changes](https://www.jessesquires.com/b
final class AppSettings: NSObject {
static let shared = AppSettings()

@WrappedDefaultOptional(key: "userId")
@FoilDefaultStorageOptional(key: "userId")
@objc dynamic var userId: String?

@WrappedDefaultOptional(key: "average")
@FoilDefaultStorageOptional(key: "average")
var average: Double?
}
```
Expand Down Expand Up @@ -122,9 +122,9 @@ AppSettings.shared

### Supported types

The following types are supported by default for use with `@WrappedDefault`.
The following types are supported by default for use with `@FoilDefaultStorage`.

> [!IMPORTANT]
> [!IMPORTANT]
> Adding support for custom types is possible by conforming to `UserDefaultsSerializable`. However, **this is highly discouraged** as all `plist` types are supported by default. `UserDefaults` is not intended for storing complex data structures and object graphs. You should probably be using a proper database (or serializing to disk via `Codable`) instead.
>
> While `Foil` supports storing `Codable` types by default, you should **use this sparingly** and _only_ for small objects with few properties.
Expand All @@ -144,8 +144,8 @@ The following types are supported by default for use with `@WrappedDefault`.
- `RawRepresentable` types
- `Codable` types

> [!WARNING]
> If you are storing custom `Codable` types and using the default implementation of `UserDefaultsSerializable` provided by `Foil`, then **you must use the optional variant of the property wrapper**, `@WrappedDefaultOptional`. This will allow you to make breaking changes to your `Codable` type (e.g., adding or removing a property). Alternatively, you can provide a custom implementation of `Codable` that supports migration, or provide a custom implementation of `UserDefaultsSerializable` that handles encoding/decoding failures. See the example below.
> [!WARNING]
> If you are storing custom `Codable` types and using the default implementation of `UserDefaultsSerializable` provided by `Foil`, then **you must use the optional variant of the property wrapper**, `@FoilDefaultStorageOptional`. This will allow you to make breaking changes to your `Codable` type (e.g., adding or removing a property). Alternatively, you can provide a custom implementation of `Codable` that supports migration, or provide a custom implementation of `UserDefaultsSerializable` that handles encoding/decoding failures. See the example below.
**Codable Example:**
```swift
Expand All @@ -156,12 +156,12 @@ struct User: Codable, UserDefaultsSerializable {
}

// Yes, do this
@WrappedDefaultOptional(key: "user")
@FoilDefaultStorageOptional(key: "user")
var user: User?

// NO, do NOT this
// This will crash if you change User by adding/removing properties
@WrappedDefault(key: "user")
@FoilDefaultStorage(key: "user")
var user = User()
```

Expand Down Expand Up @@ -190,14 +190,14 @@ var user = User()
### [CocoaPods](http://cocoapods.org)

````ruby
pod 'Foil', '~> 4.0.0'
pod 'Foil', '~> 5.0.0'
````

### [Swift Package Manager](https://swift.org/package-manager/)

```swift
dependencies: [
.package(url: "https://github.com/jessesquires/Foil.git", from: "4.0.0")
.package(url: "https://github.com/jessesquires/Foil.git", from: "5.0.0")
]
```

Expand Down
9 changes: 5 additions & 4 deletions docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Protocols Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">Foil 4.0.1 Docs</a> (100% documented)</p>
<p><a href="index.html">Foil 5.0.0 Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/jessesquires/Foil"><img src="img/gh.png" alt="GitHub"/>View on GitHub</a></p>
<div class="header-right">
<form role="search" action="search.json">
Expand Down Expand Up @@ -48,10 +48,10 @@
<a href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Structs/WrappedDefault.html">WrappedDefault</a>
<a href="Structs/FoilDefaultStorage.html">FoilDefaultStorage</a>
</li>
<li class="nav-group-task">
<a href="Structs/WrappedDefaultOptional.html">WrappedDefaultOptional</a>
<a href="Structs/FoilDefaultStorageOptional.html">FoilDefaultStorageOptional</a>
</li>
</ul>
</li>
Expand Down Expand Up @@ -98,6 +98,7 @@ <h1>Protocols</h1>
<li><code>Set</code></li>
<li><code>Dictionary</code></li>
<li><code>RawRepresentable</code> types</li>
<li><code>Codable</code> types</li>
</ul>

<a href="Protocols/UserDefaultsSerializable.html" class="slightly-smaller">See more</a>
Expand All @@ -118,7 +119,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-09)</p>
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-11)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
17 changes: 9 additions & 8 deletions docs/Protocols/UserDefaultsSerializable.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="UserDefaultsSerializable Protocol Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">Foil 4.0.1 Docs</a> (100% documented)</p>
<p><a href="../index.html">Foil 5.0.0 Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/jessesquires/Foil"><img src="../img/gh.png" alt="GitHub"/>View on GitHub</a></p>
<div class="header-right">
<form role="search" action="../search.json">
Expand Down Expand Up @@ -48,10 +48,10 @@
<a href="../Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Structs/WrappedDefault.html">WrappedDefault</a>
<a href="../Structs/FoilDefaultStorage.html">FoilDefaultStorage</a>
</li>
<li class="nav-group-task">
<a href="../Structs/WrappedDefaultOptional.html">WrappedDefaultOptional</a>
<a href="../Structs/FoilDefaultStorageOptional.html">FoilDefaultStorageOptional</a>
</li>
</ul>
</li>
Expand Down Expand Up @@ -86,6 +86,7 @@ <h1>UserDefaultsSerializable</h1>
<li><code>Set</code></li>
<li><code>Dictionary</code></li>
<li><code>RawRepresentable</code> types</li>
<li><code>Codable</code> types</li>
</ul>

</section>
Expand Down Expand Up @@ -149,24 +150,24 @@ <h4>Declaration</h4>
<li class="item">
<div>
<code>
<a name="/s:4Foil24UserDefaultsSerializableP11storedValuex06StoredF0Qz_tcfc"></a>
<a name="/s:4Foil24UserDefaultsSerializableP11storedValuexSg06StoredF0Qz_tcfc"></a>
<a name="//apple_ref/swift/Method/init(storedValue:)" class="dashAnchor"></a>
<a class="token" href="#/s:4Foil24UserDefaultsSerializableP11storedValuex06StoredF0Qz_tcfc">init(storedValue:<wbr>)</a>
<a class="token" href="#/s:4Foil24UserDefaultsSerializableP11storedValuexSg06StoredF0Qz_tcfc">init(storedValue:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Initializes the object using the provided value.</p>
<p>Initializes the object using the provided value, or returns <code>nil</code> if initialization fails.</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="nf">init</span><span class="p">(</span><span class="nv">storedValue</span><span class="p">:</span> <span class="kt"><a href="../Protocols/UserDefaultsSerializable.html#/s:4Foil24UserDefaultsSerializableP11StoredValueQa">StoredValue</a></span><span class="p">)</span></code></pre>
<pre class="highlight swift"><code><span class="nf">init</span><span class="p">?(</span><span class="nv">storedValue</span><span class="p">:</span> <span class="kt"><a href="../Protocols/UserDefaultsSerializable.html#/s:4Foil24UserDefaultsSerializableP11StoredValueQa">StoredValue</a></span><span class="p">)</span></code></pre>

</div>
</div>
Expand Down Expand Up @@ -197,7 +198,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-09)</p>
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-11)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
28 changes: 14 additions & 14 deletions docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Structures Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">Foil 4.0.1 Docs</a> (100% documented)</p>
<p><a href="index.html">Foil 5.0.0 Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/jessesquires/Foil"><img src="img/gh.png" alt="GitHub"/>View on GitHub</a></p>
<div class="header-right">
<form role="search" action="search.json">
Expand Down Expand Up @@ -48,10 +48,10 @@
<a href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Structs/WrappedDefault.html">WrappedDefault</a>
<a href="Structs/FoilDefaultStorage.html">FoilDefaultStorage</a>
</li>
<li class="nav-group-task">
<a href="Structs/WrappedDefaultOptional.html">WrappedDefaultOptional</a>
<a href="Structs/FoilDefaultStorageOptional.html">FoilDefaultStorageOptional</a>
</li>
</ul>
</li>
Expand All @@ -70,9 +70,9 @@ <h1>Structures</h1>
<li class="item">
<div>
<code>
<a name="/s:4Foil14WrappedDefaultV"></a>
<a name="//apple_ref/swift/Struct/WrappedDefault" class="dashAnchor"></a>
<a class="token" href="#/s:4Foil14WrappedDefaultV">WrappedDefault</a>
<a name="/s:4Foil0A14DefaultStorageV"></a>
<a name="//apple_ref/swift/Struct/FoilDefaultStorage" class="dashAnchor"></a>
<a class="token" href="#/s:4Foil0A14DefaultStorageV">FoilDefaultStorage</a>
</code>
</div>
<div class="height-container">
Expand All @@ -83,14 +83,14 @@ <h1>Structures</h1>
<p>A property wrapper that uses <code>UserDefaults</code> as a backing store,
whose <code>wrappedValue</code> is non-optional and registers a <strong>non-optional default value</strong>.</p>

<a href="Structs/WrappedDefault.html" class="slightly-smaller">See more</a>
<a href="Structs/FoilDefaultStorage.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@propertyWrapper</span>
<span class="kd">public</span> <span class="kd">struct</span> <span class="kt">WrappedDefault</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="Protocols/UserDefaultsSerializable.html">UserDefaultsSerializable</a></span></code></pre>
<span class="kd">public</span> <span class="kd">struct</span> <span class="kt">FoilDefaultStorage</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="Protocols/UserDefaultsSerializable.html">UserDefaultsSerializable</a></span></code></pre>

</div>
</div>
Expand All @@ -100,9 +100,9 @@ <h4>Declaration</h4>
<li class="item">
<div>
<code>
<a name="/s:4Foil22WrappedDefaultOptionalV"></a>
<a name="//apple_ref/swift/Struct/WrappedDefaultOptional" class="dashAnchor"></a>
<a class="token" href="#/s:4Foil22WrappedDefaultOptionalV">WrappedDefaultOptional</a>
<a name="/s:4Foil0A22DefaultStorageOptionalV"></a>
<a name="//apple_ref/swift/Struct/FoilDefaultStorageOptional" class="dashAnchor"></a>
<a class="token" href="#/s:4Foil0A22DefaultStorageOptionalV">FoilDefaultStorageOptional</a>
</code>
</div>
<div class="height-container">
Expand All @@ -113,14 +113,14 @@ <h4>Declaration</h4>
<p>A property wrapper that uses <code>UserDefaults</code> as a backing store,
whose <code>wrappedValue</code> is optional and <strong>does not provide default value</strong>.</p>

<a href="Structs/WrappedDefaultOptional.html" class="slightly-smaller">See more</a>
<a href="Structs/FoilDefaultStorageOptional.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@propertyWrapper</span>
<span class="kd">public</span> <span class="kd">struct</span> <span class="kt">WrappedDefaultOptional</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="Protocols/UserDefaultsSerializable.html">UserDefaultsSerializable</a></span></code></pre>
<span class="kd">public</span> <span class="kd">struct</span> <span class="kt">FoilDefaultStorageOptional</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="Protocols/UserDefaultsSerializable.html">UserDefaultsSerializable</a></span></code></pre>

</div>
</div>
Expand All @@ -132,7 +132,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-09)</p>
<p>&copy; 2024 <a class="link" href="https://jessesquires.com" target="_blank" rel="external noopener">Jesse Squires</a>. All rights reserved. (Last updated: 2024-01-11)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit f5d6633

Please sign in to comment.