Created
June 10, 2014 22:43
-
-
Save comfly/7b546f660f8976040e13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContextProvider { | |
struct _$ { | |
static let model = NSManagedObjectModel.mergedModelFromBundles(nil) | |
static let coordinator: NSPersistentStoreCoordinator = { | |
let result = NSPersistentStoreCoordinator(managedObjectModel: model) | |
var error: NSError? | |
let store = result.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: URL, options: nil, error: &error) | |
if !store { | |
NSLog("Error creating store coordinator: %@", error!) | |
} | |
return result | |
}() | |
static let URL = (NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)[0] as NSURL).URLByAppendingPathComponent("db.sqlite", isDirectory: false) | |
} | |
func context() -> NSManagedObjectContext { | |
let result = NSManagedObjectContext() | |
result.persistentStoreCoordinator = _$.coordinator | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment