kusumoto_teruya kusumoto_teruya - 2 years ago 179
Objective-C Question

Insert data with MagicalRecord

I am using


I'd like to insert
in following code,
but to insert data become an error with a message
Cocoa error 133000


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"class_schedule.sqlite"];

return YES;


- (void)saveData
Data *data = [Data MR_createEntity];
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
Data *localData = [data MR_inContext:localContext];
localData.title = textField.text;
} completion:^(BOOL success, NSError *error) {


@interface Data : NSManagedObject

@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * title;


Can you tell me how to insert record with Magical Record?

Answer Source


  • Cocoa error 133000 is:

NSManagedObjectReferentialIntegrityError = 133000, // attempt to fire a fault pointing to an object that does not exist (we can see the store, we can't see the object)

  • (Taken from this SO question). Basically you are doing something with a NSManagedObject that doesn't exist.

Inserting data:

  • In terms of how to insert data using magical record take a look at this tutorial which will probably explain it much better than I can.

My advice:

  • Use Core Data straight up. It's quite a steep learning curve, but very quickly becomes intuitive and easy to use. It will also stand you in good stead if you know how it all works rather than relying on a third party.

  • If you're interested in how it works at a more fundamental level, take a look at SQLite. I wouldn't necessarily recommend using it as it is a C library but it will help you get a deeper understanding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download