"[String: String]" Means a dictionary where the keys and the values are Strings.
"[[String: String]]" Means an array that contains dictionaries where the keys and values are strings.
create a dictionary of string and an array to hold them
let dictionary: [String: String] = ["keyOne" : "valueOne", "keyTwo": "valueTwo"]
let arrayWithDictionaryOfStrings: [[String: String]] = [dictionary]
add the array to userDefaults
let userDefaults = UserDefaults.standard
userDefaults.set(arrayWithDictionaryOfStrings, forKey: "arrayWithDictionaryOfStrings")
userDefaults.synchronize();
get the array of dictionaries from the userdefaults
if let fetchedArrayWithDictionaryOfStrings: [[String: String]] = (userDefaults.object(forKey: "arrayWithDictionaryOfStrings") as? [[String: String]]) {
// handle fetchedArrayWithDictionaryOfStrings
}
[String:String]
is not an array, by the way... And you don't need.synchronize()
. - Eric Aya