Core data 核心数据搜索错误(使用NSString)

Core data 核心数据搜索错误(使用NSString),core-data,ios7,Core Data,Ios7,我有用于核心数据的搜索问题 -案例1//它不起作用 -(BOOL)isHeThere:(NSString*)tmpIdm{ NSString *idm = [tmpIdm uppercaseString]; NSLog(@"%@",idm); AppDelegate* appDelegate = [UIApplication sharedApplication].delegate; NSFetchRequest *request = [[NSFetchRequ

我有用于核心数据的搜索问题

-案例1//它不起作用

-(BOOL)isHeThere:(NSString*)tmpIdm{

    NSString *idm = [tmpIdm uppercaseString];
    NSLog(@"%@",idm);

    AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    NSFetchRequest *request = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"HRData"
                                              inManagedObjectContext:appDelegate.managedObjectContext];
    [request setEntity:entity];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userIdm" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [request setSortDescriptors:sortDescriptors];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userIdm=%@",idm];
    [request setPredicate:predicate];

    NSError *error = nil;
    NSArray *fetchResults = [appDelegate.managedObjectContext executeFetchRequest:request
                                                                     error:&error];

    NSLog(@"%@",fetchResults);
 // cut follow code
}
日志是

2014-04-16 15:07:25.716 MyProject[693:60b] 011204121413310F
2014-04-16 15:07:25.734 MyProject[693:60b] (
)
结果什么都没有

但是

-案例2/成功了

-(BOOL)isHeThere:(NSString*)tmpIdm{

    NSString *idm = [tmpIdm uppercaseString];
    NSLog(@"%@",idm);

    AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    NSFetchRequest *request = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"HRData"
                                              inManagedObjectContext:appDelegate.managedObjectContext];
    [request setEntity:entity];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userIdm" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [request setSortDescriptors:sortDescriptors];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userIdm=%@",@"011204121413310F"];
    [request setPredicate:predicate];

    NSError *error = nil;
    NSArray *fetchResults = [appDelegate.managedObjectContext executeFetchRequest:request
                                                                     error:&error];

    NSLog(@"%@",fetchResults);

// cut follow code
]
日志是

2014-04-16 15:05:45.198 MyProject[681:60b] 011204121413310F
2014-04-16 15:05:45.220 MyProject[681:60b] (
    "<HRData: 0x16534d30> (entity: HRData; id: 0x165381e0 <x-coredata://9319373D-1532-42E0-A366-57E5B6E3EBD0/HRData/p47914> ; data: <fault>)"
)
2014-04-16 15:05:45.198我的项目[681:60b]01120421413310F
2014-04-16 15:05:45.220我的项目[681:60b](
“(实体:HRData;id:0x165381e0;数据:)”
)
两个案例使用了相同的代码“1234F”

为什么我会得到不同的结果

有什么问题吗

+我重新编辑代码(并编译日志)

如下所示

NSPredicate *pred=[NSPredicate predicateWithFormat:@"userIdm=%@",idm];
NSLog(@"%@",pred);
日志


\n在您的实际代码中可能存在一些微妙的问题,我们无法看到,因为您在这里修改了它,或者重新输入了它。你可能已经纠正了自己的错误。上面的代码甚至无法编译。一种猜测是,您在实际代码中意外使用了
tmpCode
,而不是
code
现在是实际代码。但是,仍然不要使用这一行“NSPredicate*谓词=[NSPredicate predicateWithFormat:@“userIdm=%@”,idm];[request setPredicate:predicate];“Used same String”01120421413310f“@Jason Cocohmm,奇怪。尝试记录谓词。它应该向您显示:
userIdm==“01120421413310f”
-是吗?或者它向你展示了其他的东西?!!!!非常感谢!!!!!!我发现了我的问题!!!!日志“userIdm==”01120421413310F\n”“[\n]
2014-04-16 15:23:19.832 SecurityGate[752:60b] userIdm == "011204121413310F
"