I am trying to add Int to an empty Array and then store its data with UserDefaults and then read it
, Here is what I am doing :
//create an empty array
var intArray = [Int]()
func addToBookMark(Number:Int) {
//Add object to array and save it
intArray.append(Number)
UserDefaults.standard.set(intArray, forKey: "bookmark")
UserDefaults.standard.synchronize()
//Read it
let array = UserDefaults.standard.array(forKey: "bookmark") as? [Int] ?? [Int]()
print(array.description)
}
//Calling the method :
addToBookMark(Number: 30)
The problem is compiler gives me an empty array: [] What is my problem ?