Saving and Loading Text in Swift

Swift 2.0
In this example we’ll assume there is a variable ‘score’ for saving the score of type Int and a HighScoreLabel to display it of type UILabel.



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 from the file we now have :

Here is how we would compare the current score to the High Score and if bigger – we would save it :

Here is how we would load the High Score: