Last active
August 29, 2015 14:07
-
-
Save dglancy/2f1e313cfcc7d61cff8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| extension NSManagedObjectContext { | |
| //MARK: - Public Properties | |
| public class var defaultContext: NSManagedObjectContext! { | |
| get { | |
| let context = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType) | |
| context.persistentStoreCoordinator = self.persistentStoreCoordinator // This provided by more extension properties | |
| return context | |
| } | |
| } | |
| } | |
| extension NSManagedObject { | |
| override convenience init() { | |
| let entity = NSEntityDescription.entityForName("Person", inManagedObjectContext: NSManagedObjectContext.defaultContext) // Person will be replaced with utility property if I get this appraoch working | |
| self.init(entity: entity!, insertIntoManagedObjectContext: NSManagedObjectContext.defaultContext) | |
| } | |
| } | |
| public class Person: NSManagedObject { | |
| @NSManaged var name: String | |
| @NSManaged var dateOfBirth: NSDate | |
| } | |
| Unit test: | |
| func testCreateEntity() { | |
| let entity = Person() // <=== compile error: Missing argument for parameter 'entity' in call | |
| XCTAssertNotNil(entity, "entity should not be nil") | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment