-
-
Save trm36/26f01bf66b90d1cc0ab5 to your computer and use it in GitHub Desktop.
Revisions
-
jkhowland revised this gist
Oct 2, 2014 . 2 changed files with 35 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ // // Stack.m // // Created by Joshua Howland on 6/12/14. // Copyright (c) 2014 DevMountain. All rights reserved. // #import <Foundation/Foundation.h> @interface Stack : NSObject + (Stack *)sharedInstance; @property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext; @end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,29 @@ // // Stack.m // // Created by Joshua Howland on 6/12/14. // Copyright (c) 2014 DevMountain. All rights reserved. // #import "Stack.h" @interface Stack () @property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; @end @implementation Stack + (Stack *)sharedInstance { static Stack *sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[Stack alloc] init]; }); return sharedInstance; } - (id)init { self = [super init]; @@ -28,6 +37,7 @@ - (void)setupManagedObjectContext { self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; self.managedObjectContext.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; NSError* error; [self.managedObjectContext.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil @@ -37,6 +47,7 @@ - (void)setupManagedObjectContext if (error) { NSLog(@"error: %@", error); } self.managedObjectContext.undoManager = [[NSUndoManager alloc] init]; } @@ -48,12 +59,12 @@ - (NSURL*)storeURL - (NSURL*)modelURL { return [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"]; } - (NSManagedObjectModel*)managedObjectModel { return [[NSManagedObjectModel alloc] initWithContentsOfURL:self.modelURL]; } @end -
jkhowland revised this gist
Jun 12, 2014 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,14 @@ @interface DBStack () @implementation DBStack - (id)init { self = [super init]; if (self) { [self setupManagedObjectContext]; } return self; } - (void)setupManagedObjectContext { self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; -
jkhowland revised this gist
Jun 12, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -47,3 +47,5 @@ - (NSManagedObjectModel*)managedObjectModel { return [[NSManagedObjectModel alloc] initWithContentsOfURL:self.modelURL]; } @end -
jkhowland created this gist
Jun 12, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ // // DBStack.m // Core Data Bank // // Created by Joshua Howland on 6/12/14. // Copyright (c) 2014 DevMountain. All rights reserved. // #import "DBStack.h" @interface DBStack () @property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; @end @implementation DBStack - (void)setupManagedObjectContext { self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; self.managedObjectContext.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; NSError* error; [self.managedObjectContext.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.storeURL options:nil error:&error]; if (error) { NSLog(@"error: %@", error); } self.managedObjectContext.undoManager = [[NSUndoManager alloc] init]; } - (NSURL*)storeURL { NSURL* documentsDirectory = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL]; return [documentsDirectory URLByAppendingPathComponent:@"db.sqlite"]; } - (NSURL*)modelURL { return [[NSBundle mainBundle] URLForResource:@"CoreDataBank" withExtension:@"momd"]; } - (NSManagedObjectModel*)managedObjectModel { return [[NSManagedObjectModel alloc] initWithContentsOfURL:self.modelURL]; }