1. 程式人生 > >Swift中Array的刪除對象

Swift中Array的刪除對象

font rem spa lec color sel bsp span 沒有

Swift中Array的刪除對象

在Swift中數組Array沒有removeObject的方法

1、找到下標

 let model_index = selectedArray.index(where: { (arr) -> Bool in

   ((selectedBeaconArray.index(of: vbModel)) != nil)

})

2、刪除下標對應的元素

if model_index != nil{

  selectedBeaconArray.remove(at: model_index ?? 0)

}

Swift中Array的刪除對象