[CLOSED] How do you read an array from UserDefaults

Hello! I'm developing a small app for the Apple Watch and I'm using UserDefaults as a way to pass data between Interface controllers.

I ran into SIGABRT when running this code:
Code Block language
var test: [Int] = defaults.object(forKey: "Number") as! [Int]


and this is the code that created and saved it:
Code Block language
var oneTimeArray = Array(repeating: 0, count: 50)
let defaults = UserDefaults.standard
defaults.set([oneTimeArray], forKey: "Number")



Answered by Claude31 in 671222022
Tou saved an array of array (with 1 element:
Code Block
defaults.set([oneTimeArray], forKey: "Number")

Change with:
Code Block
defaults.set(oneTimeArray, forKey: "Number")


Don't forget to close the thread if everything works OK.
Accepted Answer
Tou saved an array of array (with 1 element:
Code Block
defaults.set([oneTimeArray], forKey: "Number")

Change with:
Code Block
defaults.set(oneTimeArray, forKey: "Number")


Don't forget to close the thread if everything works OK.
[CLOSED] How do you read an array from UserDefaults
 
 
Q