Is it just for one user? If so, you could probably do it with NSUserDefaults
In ScoreView
let userDefaults = NSUserDefaults.standardUserDefaults()
If you want to store as Int for comparing current to high score
func saveScoreData(score: Int, ansQs: Int, incAns: Int) {
userDefaults.setInteger(score, forKey: "Score")
userDefaults.setInteger(ansQs, forKey: "AnsweredQuestions")
userDefaults.setInteger(incAns, forKey: "IncorrectAnswers")
userDefaults.synchronized()
}
You can call it to save wherever you think is best.
When you need to retrieve the data, you can call each one individually using their keys.
userDefaults.integerForKey("Score")
To save an array of Integers
var allScores = [5,6,10]
func addNewScore(scores: [Int], newScore: Int) {
allScores.append(newScore)
defaults.setObject([1,2,3], forKey: "AllScores")
When you call it, you need to cast it as an array of integers:
let x = defaults.objectForKey("AllScores") as [Int]
That should do it.