       assertionFailure("model with name: \(name).momd not foun")
     }
     
-    class func storeCoordinator(name:String, mom: NSManagedObjectModel, errorHandler: ErrorHandler) -> NSPersistentStoreCoordinator {
-      
-      let coordinator = NSPersistentStoreCoordinator(managedObjectModel: mom)
-      var error: NSError?
-      
-      let url = NSURL.fileURLWithPath(FileHelper.filePath("\(name).sqlite"))
-      
-      if coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
-        errorHandler.handle(error!)
-      }
-      return coordinator
-    }
+// MARK:- NSManagedObjectContext
     
-    class func mainMOC (storeCoordinator:  NSPersistentStoreCoordinator) -> NSManagedObjectContext {
+    final class func mainMOC (storeCoordinator:  NSPersistentStoreCoordinator) -> NSManagedObjectContext {
       let managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
-      
       managedObjectContext.persistentStoreCoordinator = storeCoordinator
       return managedObjectContext
     }
+    
   }
 }
 

  }
}

//MARK: - Factory
extension PersistenceLayer {

  class Factory {
    

import CoreData
import Sweet


public enum StoreLocationType {
  case PrivateFolder //Located in Documents directory. Visible only to the app
  case SharedGroup // Located in shared Group directory and visible to all exntesion that have access to that group
}

public enum StoreType {
  case SQLite
  case Binary
  case InMemory
}

public class PersistenceLayer {
  
  private let coreDataName: String
  public var errorHandler: ErrorHandler

  public var mainMOC: NSManagedObjectContext
  var managedObjectModel: NSManagedObjectModel
  var persistentStoreCoordinator: NSPersistentStoreCoordinator
  
  public init(name: String, type: StoreType = .SQLite, location: StoreLocationType = .PrivateFolder, errorHandler: ErrorHandler) {
    coreDataName = name
    self.errorHandler = errorHandler
    
    managedObjectModel = Factory.defaultMOM(coreDataName)
    persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel)
    PersistenceLayer.setupCoordinator(persistentStoreCoordinator, name:name, type: type, location: location, errorHandler: errorHandler)
    mainMOC = Factory.mainMOC(persistentStoreCoordinator)
  }

  public convenience init(name: String, fileLocation: String) {
    self.init(name: name, errorHandler: ErrorHandler())
  }
  
  public convenience init(name: String) {
    self.init(name: name, errorHandler: ErrorHandler())
  }
  public convenience init() {
    self.init(name: AppInfo.productName)
  }
}

