📜  indexset 中的 swift ge 数组项 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:01.862000             🧑  作者: Mango

代码示例1
func delete(at offsets: IndexSet) {

    // preserve all ids to be deleted to avoid indices confusing
    let idsToDelete = offsets.map { self.contacts[$0].id }

    // schedule remote delete for selected ids
    _ = idsToDelete.compactMap { [weak self] id in
        self?.deleteRequest(id){ success in
            if success {
                DispatchQueue.main.async {
                    // update on main queue
                    self?.contacts.removeAll { $0.id == id }
                }
            }
        }
    }
}