Swift 3 Core Data Delete Object

后端 未结 8 2150
日久生厌
日久生厌 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:24

    Swift 4 without using string for Entity

    let fetchRequest: NSFetchRequest = Profile.fetchRequest()
    fetchRequest.predicate = Predicate.init(format: "profileID==\(withID)")
    
    do {
        let objects = try context.fetch(fetchRequest)
        for object in objects {
            context.delete(object)
        }
        try context.save()
    } catch _ {
        // error handling
    }
    

提交回复
热议问题