From 06c0c96246d0ee2d0e7e7b56df40a5c3ada258a6 Mon Sep 17 00:00:00 2001 From: ApolloZhu Date: Fri, 16 Aug 2019 16:54:47 +0800 Subject: [PATCH] Documentation on composition --- README.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 41c2a6b..42169a3 100644 --- a/README.md +++ b/README.md @@ -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.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 +```