modo-studio / SugarRecord

CoreData/Realm sweet wrapper written in Swift
MIT License
2.11k stars 223 forks source link

Is it possible to delete all data (for example when user logs out) of core data? Not the models but data in the models #337

Closed mabdullahsaeed closed 7 years ago

mabdullahsaeed commented 7 years ago

Using SugarRecord with Swift 3. Is it possible to delete all data (for example when user logs out) of core data? Not the models/entities but data in the models/entities?

My SugarRecordManager.swift

  class SugarRecordManager
  {
  static let sharedInstance = SugarRecordManager()
   private init(){

   }

// Initializing CoreDataDefaultStorage
func coreDataStorage() -> CoreDataDefaultStorage {
    let store = CoreDataStore.named("db")
    let bundle = Bundle(for: type(of: self))
    let model = CoreDataObjectModel.merged([bundle])
    let defaultStorage = try! CoreDataDefaultStorage(store: store, model: model)
    return defaultStorage
}

// other functions for fetching and storing objects

// want to write a function here to wipe out all data
}
pepicrft commented 7 years ago

Hey @mabdullahsaeed, it's possible to delete all the data calling the method removeStore() on your storage. Let me know if that helps. https://github.com/carambalabs/SugarRecord/blob/master/SugarRecord/Source/CoreData/Storages/CoreDataDefaultStorage.swift#L104