简体   繁体   中英

How to append values to array of type [[String:String]] in Swift

I'm working with this kind of array.

var myArray : [[String:String]] = [["1" : "Arun", "2" : "Gupta"],["1" : "John", "2" : "Cena"],["1" : "James" , "2" : "Bond"],["1" : "Iron", "2" : "Man"],["1" : "Karthik","2" : "Keyan"]]

I could assign values directly to this array and access the values through object. For example,

To access values in index zero.

let obj = myArray[0]
print(obj["1"],obj["2"])

it prints values in myArray[0]

Output:

Arun Gupta.

Now what i want is, how to append values to this kind of array instead of directly assigning values in the declaration itself.

Try this :

var array1 = ["1" : "Arun", "2" : "Gupta"]

myArray.append(array1)

Try append()

var myArray = [[String:String]]()
myArray.append(["1" : "Arun", "2" : "Gupta"])
print(myArray)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM