I have data stored in a [NSDictionary]()
here is how I add the data:
var usedObjectDictionaries = [NSDictionary]()
for firstUseItem in useItemsInFirstObject {
let dict = firstUseItem.toDictionary()
usedObjectDictionaries.append(dict)
}
And the [NSDictionary]()
if printed out looks like this:
What I need to do is reach the value of the ActivityReference1
in the [NSDictionary]()
. Meaning , how can I get to the Job
.
for item in usedObjectDictionaries {
print(item["ActivityReference1"])
}
要获得第一个:
usedObjectDictionaries[0]["ActivityReference1"]
@MarieDM's answer of using array indexing will work, but it will crash if the array is empty.
You could also use
if let activity = userObjectDictionaries.first["ActivityReference1"] {
//here "activity" contains the entry from the first entry
} else {
//This code will execute
//if there are no entries in userObjectDictionaries
}
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.