Created
April 23, 2017 09:55
-
-
Save cristibaluta/ce69a5a496e6619143a639ec55105e98 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
import CloudKit | |
public extension UserDefaults { | |
var serverChangeToken: CKServerChangeToken? { | |
get { | |
guard let data = self.value(forKey: "ChangeToken") as? Data else { | |
return nil | |
} | |
guard let token = NSKeyedUnarchiver.unarchiveObject(with: data) as? CKServerChangeToken else { | |
return nil | |
} | |
return token | |
} | |
set { | |
if let token = newValue { | |
let data = NSKeyedArchiver.archivedData(withRootObject: token) | |
self.set(data, forKey: "ChangeToken") | |
self.synchronize() | |
} else { | |
self.removeObject(forKey: "ChangeToken") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment