Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fuck You CoreData!

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Fuck You CoreData!

Avatar for Ricardo Caballero

Ricardo Caballero

February 11, 2013

Other Decks in Programming

Transcript

  1. CoreData & Xcode Inconvenientes - Actualización del modelo compleja y

    tediosa - Vista en formato “esquema” prácticamente inutil
  2. Multiples contextos En iOS 5 http://www.cocoanetics.com/2012/07/multi-context-coredata/ NSMangedObjectContext *temporaryContext = [[NSManagedObjectContext

    alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; temporaryContext.parentContext = mainMOC; [temporaryContext performBlock:^{ // do something that takes some time asynchronously using the temp context // push to parent NSError *error; if (![temporaryContext save:&error]) { // handle error } // save parent to disk asynchronously [mainMOC performBlock:^{ NSError *error; if (![mainMOC save:&error]) { // handle error } }]; }];
  3. MagicalRecord + (void) setupCoreDataStackWithStoreNamed: (NSString *)storeName; NSArray *peopleSorted = [Person

    findAllSortedByProperty:@"LastName,FirstName" ascending:YES]; ¿NSManagedObjectContext?
  4. MagicalRecord Unit Test - (void)setUp; { [MagicalRecord setDefaultModelWithClass:[self class]]; [MagicalRecord

    setupCoreDataStackWithInMemoryStore]; } - (void)tearDown; { [MagicalRecord cleanUp]; } - (void)testSomeCalculationOnMyEntity; { MyEntity *testEntity = [MyEntity MR_createEntity]; float expectedValue = …; STAssert([testEntity customCalculation] == expectedValue, @"expected a good calculation"); } @end http://www.cimgf.com/2012/05/15/unit-testing-with-core-data/
  5. Mogenerator Foo/ | |- Foo.xcodeproj | |- Foo/ | |

    | |- en.lproj | | FooAppDelegate.h | | FooAppDelegate.m | | ViewController.h | | ViewController.m | | etc | | | |- CoreData/ | | | |- Human | | | | | |- <editable files will go here> | | | |- Machine/ | | | |- <system files will go here> | |- FooTests/ | |- etc
  6. Mogenerator #import <CoreData/CoreData.h> #import "MTManagedObject.h" extern const struct NoteAttributes {

    __unsafe_unretained NSString *body; __unsafe_unretained NSString *date; __unsafe_unretained NSString *keywords; __unsafe_unretained NSString *title; } NoteAttributes; extern const struct NoteRelationships { } NoteRelationships; extern const struct NoteFetchedProperties { } NoteFetchedProperties; @interface NoteID : NSManagedObjectID {} @end @interface _Note : MTManagedObject {} + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; + (NSString*)entityName; + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; - (NoteID*)objectID; @property (nonatomic, strong) NSString* body; @property (nonatomic, strong) NSDate* date; @property (nonatomic, strong) NSString* keywords; @property (nonatomic, strong) NSString* title; @end @interface _Note (CoreDataGeneratedAccessors) @end Machine