在String,Int等类型的数组中找到一个元素非常简单.
var States = ["CA","FL","MI"] var filteredStates = States.filter {$0 == "FL"} // returns false,true,false
现在,我创建了一个结构体
struct Candy{ let name:String }
然后初始化它
var candies = [Candy(name: "Chocolate"),Candy(name: "Lollipop"),Candy(name: "Caramel")]