Len_X
Len_X

Reputation: 873

Swift : [NSDictionary]()

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:

enter image description here

What I need to do is reach the value of the ActivityReference1 in the [NSDictionary](). Meaning , how can I get to the Job.

Upvotes: 0

Views: 311

Answers (3)

Duncan C
Duncan C

Reputation: 131491

@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
}

Upvotes: 0

Marie Dm
Marie Dm

Reputation: 2727

To get the first one:

usedObjectDictionaries[0]["ActivityReference1"]

Upvotes: 0

shallowThought
shallowThought

Reputation: 19602

for item in usedObjectDictionaries {
    print(item["ActivityReference1"])
}

Upvotes: 2

Related Questions