Skip to content

Commit

Permalink
Documentation on composition
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloZhu committed Aug 16, 2019
1 parent 8774b8c commit 06c0c96
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,43 @@ which can be simplified as
UserDefaults.efStorage.someKey as String?
```

and assign through
and assign the content through

```swift
UserDefaults.efStorage.someKey = "OwO"
```

### Non-default Container

Should you need to use a different instance, you can do that too

```swift
@EFStorageUserDefaults(forKey: "anotherKey", defaultsTo: true,
in: UserDefaults.standard, persistDefaultContent: true)
in: UserDefaults.standard,
persistDefaultContent: true)
var inAnotherStorage: Bool

UserDefaults.standard.efStorage.anotherKey // either reference or content
UserDefaults.standard.efStorage.anotherKey // either content or the reference to it

EFStorageUserDefaultsRef<Bool>.forKey("anotherKey", in: UserDefaults.standard)
```

### Supported Containers

As of now, we offer support for `UserDefaults` and `Keychain` (provided by `KeychainAccess`).
You can combine them to form a new type of container, or to support previous keys.

```swift
@EFStorageComposition(
EFStorageUserDefaults(forKey: "isNewUser", defaultsTo: false),
EFStorageKeychainAccess(forKey: "isNewUser", defaultsTo: false))
var isNewUser: Bool

@AnyEFStorage(
EFStorageKeychainAccess(forKey: "paidBefore", defaultsTo: false)
+ EFStorageUserDefaults(forKey: "paidBefore", defaultsTo: false)
+ EFStorageUserDefaults(forKey: "oldHasPaidBeforeKey",
defaultsTo: true,
persistDefaultContent: true))
var hasPaidBefore: Bool
```

0 comments on commit 06c0c96

Please sign in to comment.