I have an array of values var studentIDs: [Int] = []
.I want to store all the values in the array on userDefaults.Please Help.
Asked
Active
Viewed 90 times
-5
-
3And the problem is ...? – Cristik Mar 09 '18 at 13:37
-
1Here: https://developer.apple.com/documentation/foundation/userdefaults – Cristik Mar 09 '18 at 13:52
-
Possible duplicate of https://stackoverflow.com/questions/25179668/how-to-save-and-read-array-of-array-in-nsuserdefaults-in-swift?noredirect=1&lq=1 – rmaddy Mar 09 '18 at 15:01
1 Answers
2
let array = [1, 2, 9, 3, 22]
UserDefaults.standard.set(array, forKey: "studentIDs")
//get id's array from user defaults
let studentIdsArray = UserDefaults.standard.array(forKey: "studentIDs")
There are plenty of questions/solutions, here is one: how to save and read array of array in NSUserdefaults in swift?
But as another user said, please take a look at the official documentation: https://developer.apple.com/documentation/foundation/userdefaults

valosip
- 3,167
- 1
- 14
- 26
-
1Instead of posting an answer with links to duplicates, simply close the question as a duplicate. – rmaddy Mar 09 '18 at 15:01