         else {
             SugarRecord.handle(error)
         }
-        
         self.persistentStore = store!
     }
     
-    public func createPathIfNecessary(forFilePath filePath:NSURL) {
+    /**
+    Creates a path if necessary in a given route
+    
+    :param: filePath NSURL with the whose folder is going to be created
+    */
+    public func createPathIfNecessary(forFilePath filePath:NSURL)
+    {
         let fileManager: NSFileManager = NSFileManager.defaultManager()
         let path: NSURL = filePath.URLByDeletingLastPathComponent!
         var error: NSError?

    
    //MARK - Database helper
    
    public func addDatabase() {
        var error: NSError?
        createPathIfNecessary(forFilePath: self.databasePath!)

                return NSURL(fileURLWithPath: databasePath)
            }
        }
        let databasePath: String = applicationPath.stringByAppendingPathComponent(name)
        return NSURL(fileURLWithPath: databasePath)
    }
    
    
    //MARK - Saving helper
    
    /**
    Apply the changes of the root saving to be persisted in the database
    */
    private func saveChangesInRootSavingContext()
    {
        if self.rootSavingContext == nil {
            assert(true, "Fatal error. The private context is not initialized")
        }
        if self.rootSavingContext!.hasChanges {
            var error: NSError?
            self.rootSavingContext!.save(&error)
            if error != nil {
                let exception: NSException = NSException(name: "Context saving exception", reason: "Pending changes in the root savinv context couldn't be saved", userInfo: ["error": error!])
                SugarRecord.handle(NSException())
            }
            else {
                SugarRecordLogger.logLevelInfo.log("Existing changes persisted to the database")
            }
        }
    }
}


/**
*  Extension to add some extra methods related with KVO like:
*   - Observing when the context is going to be saved to get permanent IDs before saving
*   - Observing when the another context changes and then bring these changes
*/
extension NSManagedObjectContext
{
    /**
    Add observer of self to check when is going to save to ensure items are saved with permanent IDs
    */
    func addObserverToGetPermanentIDsBeforeSaving() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("contextWillSave:"), name: NSManagedObjectContextWillSaveNotification, object: self)
    }
    
    /**
    Method executed before saving that convert temporary IDs into permanet ones
    
    :param: notification Notification that fired this method
    */
    func contextWillSave(notification: NSNotification) {
        let context: NSManagedObjectContext = notification.object as NSManagedObjectContext
        let insertedObjects: NSSet = context.insertedObjects
        if insertedObjects.count == 0{
            return
        }
        SugarRecordLogger.logLevelInfo.log("Saving: obtaining permanent IDs for \(insertedObjects.count) new inserted objects")
        var error: NSError?
        let saved: Bool = context.obtainPermanentIDsForObjects(insertedObjects.allObjects, error: &error)
        if !saved {
            SugarRecordLogger.logLevelError.log("Error moving temporary IDs into permanent ones - \(error)")
        }
    }
    
    /**
    Add observer of other context
    
    :param: context    NSManagedObjectContext to be observed
    :param: mainThread Bool indicating if it's the main thread
    */
    func startObserving(context: NSManagedObjectContext, inMainThread mainThread: Bool) {
        if mainThread {
            NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("mergeChangesInMainThread:"), name: NSManagedObjectContextDidSaveNotification, object: context)
        }
        else {
            NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("mergeChanges:"), name: NSManagedObjectContextDidSaveNotification, object: context)
        }
    }
    
    /**
    Stop observing changes from other contexts
    
    :param: context NSManagedObjectContext that is going to stop observing to
    */
    func stopObserving(context: NSManagedObjectContext) {
        NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextDidSaveNotification, object: nil)
    }
    
    /**
    Method to merge changes from other contexts (fired by KVO)
    
    :param: notification Notification that fired this method call
    */
    func mergeChanges(fromNotification notification: NSNotification) {
        SugarRecordLogger.logLevelInfo.log("Merging changes from context: \((notification.object as NSManagedObjectContext).name) to context \(self.name)")
        self.mergeChangesFromContextDidSaveNotification(notification)
    }
    
    /**
    Method to merge changes from other contexts (in the main thread)
    
    :param: notification Notification that fired this method call
    */
    func mergeChangesInMainThread(fromNotification notification: NSNotification) {
        dispatch_async(dispatch_get_main_queue(), {
            self.mergeChanges(fromNotification: notification)
        })
    }
}