I am trying to check if a specific item (value of a property) exists in a array of objects, but could not find out any solution. Please let me know, what i am missing here.
class Name {
var id : Int
var name : String
init(id:Int, name:String){
self.id = id
self.name = name
}
}
var objarray = [Name]()
objarray.append(Name(id: 1, name: "Nuibb"))
objarray.append(Name(id: 2, name: "Smith"))
objarray.append(Name(id: 3, name: "Pollock"))
objarray.append(Name(id: 4, name: "James"))
objarray.append(Name(id: 5, name: "Farni"))
objarray.append(Name(id: 6, name: "Kuni"))
if contains(objarray["id"], 1) {
println("1 exists in the array")
}else{
println("1 does not exists in the array")
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…