Hey guys so I know that we can append single string to userdefault but I was wondering how we can append [String: String]
So here is my code
var savedArray = UserDefaults.standard.array(forKey: "array1") as! [String]
let name = John
let lastname = Smith
if let index = savedArray?.index(where: {$0 != name!}) {
savedArray?.append(name!)
}
//this code works fine but now I want to add more than just name. So I tried this code below
if let index = savedArray?.index(where: {$0 != name!}) {
savedArray?.append(name!, lastname!)
}
But then I get a error that says extra argument in call. So I am assuming that because on top I put as! [String]. But if I put
var savedArray = UserDefaults.standard.array(forKey: "array1") as! [String: String]
I can't append this variable because the error message says that append is not available for String: String. Is there anyway to append multiple strings into a Userdefault? When I tried to google this it only shows how to set your userdefaults to the strings but I want to keep adding values into the userdefaults.