0

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.

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you for giving answer. but i need answer in swift language. please give me answer in swift @Balaji
Upvoted :) Good solution. I would check the error at the end, and also instead of var arr: [AnyObject], I would cast it to the type of entity it is, e.g. Register (assuming that register inherits from NSManagedObject)
thank you for giving answer in swift @BalajiRamakrishnan

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.