2014-11-04 69 views
1

刪除一個給定的值我有斯威夫特從一個數組

var specs : [String] = [Button1,Button2,Button3,Button4] 

一個簡單的數組我怎麼能在我的erray查找某一值(類型將Button3),因此取消?

+0

發現(規格,Button3) – HAS 2014-11-04 21:02:45

回答

2

可以使用find()全局函數來檢索索引:

var specs : [String] = ["Button1","Button2","Button3","Button4"] 

let index = find(specs, "Button3") 

,然後,一經查實,該元素存在(find回報可選),將其刪除:

if let index = index { 
    specs.removeAtIndex(index) 
} 
+0

並刪除值 – 2014-11-04 21:06:47

+0

你是什麼意思? – Antonio 2014-11-04 21:07:33

+0

好的,謝謝[關閉] – 2014-11-04 21:11:54