
Saving and Loading Text in Swift
Here is a full solution on saving and loading text with Swift 2.0, current example is for saving and loading high score in a game.
Using those 2 functions we can now declare a variable to store a path to our highscore text file:
Here is how we would load text […]
1 2 3 4 5 6 7 8 9 10 11 |
func getDocumentsURL() -> NSURL { let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] return documentsURL } func fileInDocumentsDirectory(filename: String) -> String { let fileURL = getDocumentsURL().URLByAppendingPathComponent(filename) return fileURL.path! } |
1 |
let scoreSavePath = fileInDocumentsDirectory("highScore.txt") |