How to iterate through array of objects in Swift? -
i have objects
var person1 = person() person1.name = "joe" person1.lastname = "doe" person1.age = 21 var person2 = person() person2.name = "julia" person2.lastname = "ivanova" person2.age = 22 var person3 = person() person3.name = "irina" person3.lastname = "petrova" person3.age = 25 var person9 = person() person9.name = "vova" person9.lastname = "vovin" person9.age = 32 var person10 = person() person10.name = "masha" person10.lastname = "golovanova" person10.age = 20 var person11 = person() person11.name = "petra" person11.lastname = "andreeva" person11.age = 27
and multi array
var array = [[person1, person2, person3], [person9, person10, person11]]
how can iterate through array example person name="masha"
thanks in advance
i try this:
var array:[[person]] = [[person1, person2, person3], [person9, person10, person11]] /*casting should keep getting error later and/or having recast objects*/ people in array { /*this going @ each array in arrays, , call each 1 'people' within loop*/ person in people { /*same thing, going @ each item in people array , call each 1 'person' within loop*/ if person.name == "masha" { return person } } }
Comments
Post a Comment