-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
  • 307,833
  • 40
  • 508
  • 550
Surya
  • 290
  • 2
  • 11

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