Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
Created May 11, 2015 08:01
Show Gist options
  • Save lordhumunguz/2b4ee93068405c701b43 to your computer and use it in GitHub Desktop.
Save lordhumunguz/2b4ee93068405c701b43 to your computer and use it in GitHub Desktop.
[iOS] Data Persistence
// ## NSUserDefaults
// Storing a value in NSUserDefaults
NSUserDefaults.standardUserDefaults().defaults.setFloat(22.5 forKey: “myValue”)
// Retrieving a value from NSUserDefaults
let value = NSUserDefaults.standardUserDefaults().floatForKey(“myValue”)
// ## File System
// Building the path for a file in the Documents directory
let filename = "usersVoice.wav"
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
let pathArray = [dirPath, filename]
let fileURL = NSURL.fileURLWithPathComponents(pathArray)!
// Checking to see if a file exists
if NSFileManager.defaultManager().fileExistsAtPath(audioFileURL().path!) {
shouldSegueToSoundPlayer = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment