-5

I have an array of values var studentIDs: [Int] = [].I want to store all the values in the array on userDefaults.Please Help.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Surya
  • 602
  • 5
  • 14

1 Answers1

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
  • 1
    Instead of posting an answer with links to duplicates, simply close the question as a duplicate. – rmaddy Mar 09 '18 at 15:01