如何在Swift中附加数组?

时间:2017-10-23 00:24:31

标签: arrays swift

这是我的数组

 var docData: [String: Any] = [
             "timestamp":Int64(Date().timeIntervalSince1970 * 1000),
             "photo": photo_uri,
             "name": name.text ?? "
             ]

我想将下一个项目添加到数组[“email”:email.text ?? “”]

以下不起作用

docData += ["email": email.text ?? ""]

1 个答案:

答案 0 :(得分:3)

You didn't create an array... you created a dictionary. In which case you would set the key to the value. A dictionary is a collection of key and value pairs.

docData["email"] = email.text ?? ""