nhyolo
nhyolo

Reputation: 61

MagicalRecord crashes on importFromObject:

I'm a little bit out if luck here. Maybe someone can point me in the right direction. I'm trying to make the MagicalRecord importFromObject method work. What I have is this:

Prefix.pch contains this:

#define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"

This code crashes:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    [MagicalRecord setupCoreDataStack]; 
    [Product importFromObject:[NSDictionary dictionaryWithObject:@"test" forKey:@"title"]]; // Crashes here with EXC_BAD_ACCESS

    ....
}

It crashes in NSManagedObject+MagicalRecord.m in this method:

+ (NSArray *) MR_executeFetchRequest:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context
{
    __block NSArray *results = nil;
    [context performBlockAndWait:^{    

        NSError *error = nil;    

        results = [context executeFetchRequest:request error:&error]; // Crashes here with EXC_BAD_ACCESS

        if (results == nil) 
        {
            [MagicalRecord handleErrors:error];
        }    

    }];
    return results; 
}

Upvotes: 3

Views: 1210

Answers (1)

Tanguy G.
Tanguy G.

Reputation: 2303

You are likely to have these kind of crashes because you did not add the attribute "productID" (Entity Name + ID) (type String) to your model.

If you don't want to add a productID attribute, you can also refer it by adding the key relatedByAttribute (value : a primary attribute of your entity) to your entity User Info.

Upvotes: 2

Related Questions