0

I am currently working with core data in swift and i want to reset my core data to blank but don't want to change the schema. Actually the problem is i am getting some data and displaying it in table view and after i logout and login with other account the old data is still there from previous account so i think i need to reset my core data.

I need solution in swift. Thanks in advance

I am trying this

class func deleteAllManagedObjects() {
    let modelURL = NSBundle.mainBundle().URLForResource("some string", withExtension: "mom")
    let mom = NSManagedObjectModel(contentsOfURL: modelURL)

    for entityName in mom.entitiesByName.keys {
        let fr = NSFetchRequest(entityName: entityName as String)
        let a = Utility.managedObjectContext().executeFetchRequest(fr, error: nil) as [NSManagedObject]
        for mo in a {
            Utility.managedObjectContext().deleteObject(mo)
        }
    }

    Utility.managedObjectContext().save(nil)
}
Manu Gupta
  • 1,759
  • 1
  • 14
  • 22

0 Answers0