Tokens
open class Tokens: NSObject, NSCoding
CloudCore’s class for storing global CKToken
objects. Framework uses one to upload or download only changed data (smart-sync).
To detect what data is new and old, framework uses CloudKit’s CKToken
objects and it is needed to be loaded every time application launches and saved on exit.
Framework stores tokens in 2 places:
- singleton
Tokens
object inCloudCore.tokens
- tokens per record inside Record Data attribute, it is managed automatically you don’t need to take any actions about that token
You need to save Tokens
object before application terminates otherwise you will loose smart-sync ability.
Example
func applicationWillTerminate(_ application: UIApplication) {
CloudCore.tokens.saveToUserDefaults()
}
-
Create fresh object without any Tokens inside. Can be used to fetch full data.
Declaration
Swift
public override init()
-
Load saved Tokens from UserDefaults. Key is used from
CloudCoreConfig.userDefaultsKeyTokens
Declaration
Swift
open static func loadFromUserDefaults() -> Tokens
Return Value
previously saved
Token
object, if tokens weren’t saved before newly initializedTokens
object will be returned -
Save tokens to UserDefaults and synchronize. Key is used from
CloudCoreConfig.userDefaultsKeyTokens
Declaration
Swift
open func saveToUserDefaults()
-
Returns an object initialized from data in a given unarchiver.
Declaration
Swift
public required init?(coder aDecoder: NSCoder)
-
Encodes the receiver using a given archiver.
Declaration
Swift
open func encode(with aCoder: NSCoder)