当我简单地调用MR_createEntity时,我得到一个exc_bad_access错误。由于我是magicalRecord的新手,我无法找到bug的来源。
代码:
TMTAppDelegate.m
//TMTAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[MagicalRecord setupAutoMigratingCoreDataStack];
NSArray *trajetsRawArray = @[@{@"km" : @125, @"mn":@110, @"adressStart" : @"Metz", @"adressEnd" : @"Gérardmer", },
@{@"km" : @4, @"mn":@14, @"adressStart" : @"Plappeville", @"adressEnd" : @"Metz"},
@{@"km" : @312, @"mn":@200, @"adressStart" : @"Metz", @"adressEnd" : @"Paris"},
@{@"km" : @413, @"mn":@236, @"adressStart" : @"Marseille", @"adressEnd" : @"Toulouse"},
@{@"km" : @2, @"mn":@4, @"adressStart" : @"Ban-St-Martin", @"adressEnd" : @"Metz"},
@{@"km" : @65, @"mn":@63, @"adressStart" : @"Metz", @"adressEnd" : @"Gérardmer"}
];
//[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"backButton"]];
self.trajetsManager = [[TMTTrajetsManager alloc]initWithArray:trajetsRawArray];
NSLog(@"hello");
return YES;
}
TMTTrajetsManager.m
// TMTTrajetsManager.m
-(id)initWithArray:(NSArray *)array {
self = [super init];
if (self){
for (NSDictionary *trajetDico in array){
Trajet *trajet = [Trajet MR_createEntity];
trajet.distance = [trajetDico objectForKey:@"km"];
trajet.duration = [trajetDico objectForKey:@"mn"];
trajet.start_point = [trajetDico objectForKey:@"adressStart"];
trajet.end_point = [trajetDico objectForKey:@"adressEnd"];
self.autoManager = [[TMTTrajetAutoManager alloc] initWithDelegate:self];
}
}
return self;
}
错误:
答案 0 :(得分:12)
禁用MR_SHORTHAND,并明确使用带有MR_前缀的方法名称。看起来这种方法通过速记支持识别出这种方法存在。现在不推荐使用速记支持,它将是MagicalRecord的removed in the next version。