应用程序需要从核心数据中检索数据,然后将其中一个值与 IF 语句进行比较
MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *getDetails = [NSEntityDescription entityForName:@"Detail" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:getDetails];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(genID = %i)", genID];
[request setPredicate:pred];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"genID" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
for (NSManagedObject *oneObject in objects) {
NSString *type = [oneObject valueForKey:@"type"];
if (type == @"straight") {
NSLog(@"straight");
//straight logic removed
}else if (type == @"Left") {
NSLog(@"Left");
//Left logic removed
}else {
NSLog(@"Else");
//Else logic removed
}
}
问题是它永远不会进入“直”或“左”总是 ELSE。单步执行代码,我可以看到值确实匹配直线和左侧,甚至将它们转储到日志文件中也显示它们很好。怎么了?