iOS & Swift 공부 - CoreData -> Delete Data from Core Data (Delete in CRUD)

김영채 (Kevin)·2021년 3월 16일
0

iOS & Swift

목록 보기
95/107
post-thumbnail

Deleting Data from Core Data (Delete in CRUD)


override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    //itemArray[indexPath.row].isDone = !itemArray[indexPath.row].isDone
        
    context.delete(itemArray[indexPath.row])
    itemArray.remove(at: indexPath.row)
        
    saveItems()
    
    tableView.deselectRow(at: indexPath, animated: true)    // cell 을 누르자마자 deselect 되는 애니메이션이 나올 수 있도록
        
}
  • The order which we delete and remove matters a huge deal.
  • We first need to delete what we want to delete from the context, or the staging area. Then, we delete the itemArray that are tableview uses as a datasource to populate the cells.
  • Then, we want to save the new results to the context, then to the persistent container.
  • So, except for Read in CRUD, you would always have to commit your changes after creating, updating, or deleting data by context.save( ).
profile
맛있는 iOS 프로그래밍

0개의 댓글