Prefix.pch包含:
#define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"
此代码崩溃:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[MagicalRecord setupCoreDataStack];
[Product importFromObject:[NSDictionary dictionaryWithObject:@"test" forKey:@"title"]]; // Crashes here with EXC_BAD_ACCESS
....
}
在此方法中,它在NSManagedObject + MagicalRecord.m中崩溃:
+ (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;
}
答案 0 :(得分:2)
您可能会遇到这类崩溃,因为您没有添加属性" productID" (实体名称+ ID)(类型字符串)到您的模型。
如果您不想添加productID属性,也可以通过将关键的RelatedByAttribute(值:您实体的主要属性)添加到您的实体用户信息来引用它。