Swift 3 Core Data Delete Object

后端 未结 8 2137
日久生厌
日久生厌 2020-11-29 02:41

Unfortunately the new Core Data semantics make me crazy. My previous question had a clean code that didn\'t work because of incorrect auto generation of header files. Now I

8条回答
  •  迷失自我
    2020-11-29 03:06

    Delete the object from core data

    let entity = NSEntityDescription.entity(forEntityName: "Students", in: managedContext)
            let request = NSFetchRequest()
            request.entity = entity
            if let result = try? managedContext.fetch(request) {
                for object in result {
                    managedContext.delete(object as! NSManagedObject)
                }
                txtName.text = ""
                txtPhone.text = ""
                txt_Address.text = ""
                labelStatus.text = "Deleted"
    
            }
    

提交回复
热议问题