I'm trying to find a way to get the value of a key in a SwiftyJSON dictionary and return a default string, if the key is not set. The following example works fine, but I'm not really satisfied. Do you know a more elegant way?
let users: JSON = [
["id": 1, "name": "one"],
["id": 2],
["id": 3, "name": "three"]
]
for (key: String, user: JSON) in users {
println(user.object.objectForKey("name") != nil
? user["name"].stringValue
: "default")
}