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.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197

1 Answers1

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.

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22
  • thank you for giving answer. but i need answer in swift language. please give me answer in swift @Balaji – kishan patel Oct 06 '15 at 06:56
  • 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) – Swinny89 Oct 06 '15 at 06:57
  • thank you for giving answer in swift @BalajiRamakrishnan – kishan patel Oct 06 '15 at 06:58