[Solved] check the value of dictionary in array in swift [closed]


Imagine you downloaded some data from the server. You will convert the data into a dictionary using

let arrayOfDictionaries = try! NSJSONSerialization.JSONObjectWithData(
    data,
    options: .AllowFragments
)

var techNames  : [String] = []
var adminNames : [String] = []

Then you can iterate doing

for dictionary in arrayOfDictionaries {

    if dictionary["department"] == "Technology" {

        // Add name to techNames
        techNames.append(completeNameForPerson(dictionary))

    } else {

        // Do something else
        adminNames.append(completeNameForPerson(dictionary))
    }
}

func completeNameForPerson(person : [String : String]) -> String {

    return "\(person["firstname"]!) \(person["lastname"]!)"
}

This is a common question, please, search before opening a new discussion thread.

2

solved check the value of dictionary in array in swift [closed]