["list": Optional([Optional(["phone": Optional("+51263153765"), "name": Optional("Peter Agent"), "__typename": Optional("User"), "email": Optional("peter@pety.com")]), Optional(["name": Optional("Thomas Agent"), "__typename": Optional("User"), "email": Optional("email@gmail.biz"), "phone": Optional("+1313131231")])]), "__typename": Optional("CompareUsers")]
How can I access the value of each element of each array in the [list Optional([..])]
So I can put use the value like so -->
let email: [String] = []
for contact in (the list) {
email.append(contact.email)
}
and same for the phone and the name, if someone got a big brain related to swift please help.
let listDictionary = ["list": Optional([Optional(["phone": Optional("+51263153765"),
"name": Optional("Peter Agent"),
"__typename": Optional("User"),
"email": Optional("peter@pety.com")]),
Optional(["name": Optional("Thomas Agent"),
"__typename": Optional("User"),
"email": Optional("email@gmail.biz"),
"phone": Optional("+1313131231")])]),
"__typename": Optional("CompareUsers")]
if let listArray = listDictionary["list"] {
for data in listArray {
if let personData = data {
if let phone = personData["phone"], let name = personData["name"], let email = personData["email"], let type = personData["__typename"] {
print("User: \(name) of type: \(type), has phone number: \(phone) and email: \(email)")
}
}
}
}
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.