Created
April 21, 2015 17:55
-
-
Save benmorrow/4b1eab50c27b5694e502 to your computer and use it in GitHub Desktop.
Alternative to NSUserDefaults write/read to filesystem (fix for glances in WatchKit on physical Apple Watch hardware)
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
var sharedContainerURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.company.project")!.URLByAppendingPathComponent("DB.plist") | |
func retrieve() -> AnyObject? { | |
if let data = NSData(contentsOfURL: sharedContainerURL) { | |
if let unarchived: AnyObject = NSKeyedUnarchiver.unarchiveObjectWithData(data) { | |
return unarchived | |
} | |
} | |
return nil | |
} | |
func save(object: AnyObject) { | |
let data = NSKeyedArchiver.archivedDataWithRootObject(object) | |
data.writeToURL(sharedContainerURL, atomically: true) | |
} | |
func destroy(){ | |
NSFileManager.defaultManager().removeItemAtURL(sharedContainerURL, error: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment