Created
February 19, 2017 09:22
-
-
Save jhonny-me/99be865068428e4219b16f2283233d17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct YourUserDefaults { | |
... | |
func set(_ value: Any?, for key: String) { | |
// some encrypt work | |
... | |
UserDefaults.standard.set(ValueAfterEncrypt, forKey: key) | |
} | |
func object(for key: String) -> Any?{ | |
let value = UserDefaults.standard.value(forKey: key) | |
// some decrypt work | |
... | |
return ValueAfterDecrypt | |
} | |
} | |
struct Manager { | |
static var datas: [SomeModel] = YourUserDefaults.standard.value(forKey: "datasKey") as? [SomeModel] ?? [] { | |
didSet { | |
DispatchQueue.global().async { | |
// some archive work, maybe map to a json Array | |
... | |
YourUserDefaults.standard.set(datas, forKey: "datasKey") | |
} | |
} | |
} | |
} | |
// all in memory | |
Manager.datas[2] = Manager.datas[0] + Manager.datas[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment