我有一個包含多個問題的數組,並且一旦它顯示問題,它就會從索引中刪除它而不會再顯示。問題是一旦應用程序重新啓動它不會保存這個。我需要能夠保存它,因此它不顯示已經顯示的問題。將自定義數組保存到用戶默認設置
這裏是數組:
questions = [question(question: "The Average Adult Human Body Contains 206 Bones", answers:["True","False"], answer: 0),
question(question: "Bees Have One Pair Of Wings", answers: ["True", "False"], answer: 1),
question(question: "The Shanghi Tower Is The Tallest Building In The World", answers: ["True", "False"], answer: 1),
question(question: "1024 Bytes Is Equal To 10 Kilobytes", answers: ["True", "False"], answer: 1)].....Plus More
這裏就是我挑選,然後取下問題:
func pickQuestion() {
if questions.count > 0 {
questionNumber = Int(arc4random_uniform(UInt32(questions.count)))
questionLabel.text = questions[questionNumber].question
answerNumber = questions[questionNumber].answer
for i in 0..<trueorfalse.count {
trueorfalse[i].setTitle(questions[questionNumber].answers[i], for: UIControlState.normal)
}
//Here is where the question is removed from the array.
questions.remove(at: questionNumber)
}
}
感謝。
檢查答案這個問題:http://stackoverflow.com/questions/25179668/how-to-save-and-read-array-of-array-in-nsuserdefaults-in-swift。 –
如何將你的數組添加到userdefault中? – KKRocks
你需要使用密鑰存檔器來存儲這種數據在NSUser默認 – KavyaKavita