Created
May 11, 2015 08:01
-
-
Save lordhumunguz/2b4ee93068405c701b43 to your computer and use it in GitHub Desktop.
[iOS] Data Persistence
This file contains hidden or 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
// ## 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