「Swift」filterメソッドで配列を生成するサンプル
書式
配列名.filter{条件}
サンプルコード
let cft = ["Meet", "Noo", "Ntt", "U009"] let result = cft.filter { (kk) in return kk.hasPrefix("N") } print(cft) print(result)
結果
[“Meet", “Noo", “Ntt", “U009"]
[“Noo", “Ntt"]
Coding Changes the World
書式
配列名.filter{条件}
サンプルコード
let cft = ["Meet", "Noo", "Ntt", "U009"] let result = cft.filter { (kk) in return kk.hasPrefix("N") } print(cft) print(result)
結果
[“Meet", “Noo", “Ntt", “U009"]
[“Noo", “Ntt"]