kishan patel
kishan patel

Reputation: 29

How to delete specific entity data from core data in Swift?

I have one entity named Register with several attributes. I want to delete all the data from the specific entity.

Please give me an answer related to iOS Swift.

Upvotes: 0

Views: 224

Answers (1)

Balaji Ramakrishnan
Balaji Ramakrishnan

Reputation: 1959

I've also searched the same and found some like below. Using a Fetch Request to Collect all objects and delete one by one.

var arr: [AnyObject] = managedObjContextIns.executeFetchRequest(fetchReq, error: &error)
for managedObj: NSManagedObject in arr 
{
  managedObjContextIns.deleteObject(managedObj)
}
var error: NSErrorPointer? = nil
managedObjContextIns.save(&error)

Hope it helps.

Upvotes: 1

Related Questions