var person1 = Person()person1.name = "Joe"person1.lastname = "Doe"person1.age = 21var person2 = Person()person2.name = "Julia"person2.lastname = "Ivanova"person2.age = 22var person3 = Person()person3.name = "Irina"person3.lastname = "Petrova"person3.age = 25var person9 = Person()person9.name = "Vova"person9.lastname = "Vovin"person9.age = 32var person10 = Person()person10.name = "Masha"person10.lastname = "Golovanova"person10.age = 20var person11 = Person()person11.name = "Petra"person11.lastname = "Andreeva"person11.age = 27
和多阵列
var array = [[person1,person2,person3],[person9,person10,person11]]
我如何迭代数组来获取例如name =“Masha”的人
提前致谢
我会试试这个:var array:[[Person]] = [[person1,person11]]/*Casting it like this should keep from getting an error later and/or having to recast the objects*/for people in array {/*This is going to look at each array in arrays,and call each one 'people' within this looP*/ for person in people { /*Same thing,this is going to look at each item in the people array and call each one 'person' within this looP*/ if person.name == "Masha" { return person } }}总结
以上是内存溢出为你收集整理的数组 – 如何遍历Swift中的对象数组?全部内容,希望文章能够帮你解决数组 – 如何遍历Swift中的对象数组?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)