2012-07-05 19 views
0

我是iPhone的首发者。我想做大小写不敏感的搜索。使用数据库帮助程序:Core Data提供DB(核心数据)不区分大小写的搜索

以下是我的代码:

-(WebAttendee *) FindAttendeeBy:(NSString *) badgeID_ 
    { 

     AppDelegate_Shared *delegate1 = [[UIApplication sharedApplication]delegate]; 


     badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"]; 

     badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]; 

     self.managedObjectContext = delegate1.managedObjectContext; 

     return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] %@",badgeID_ ]]; 


    } 
    -(NSManagedObject *)FetchManagedObject:(NSString *)entity_:(NSString *)predicate_ 
     { 

      NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
      NSEntityDescription *entity = [NSEntityDescription entityForName:entity_ inManagedObjectContext:managedObjectContext]; 
      [request setEntity:entity]; 

      NSPredicate *predicate = [NSPredicate predicateWithFormat:predicate_]; 
      [request setPredicate:predicate]; 

      NSError *error = nil; 

//--------------------------crashes at this step---------------------------------   
      mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; 

      NSLog(@"FetchResult=%@",mutableFetchResults); 
      [request release]; 
      if (mutableFetchResults == nil) { 
       // Handle the error. 
      } 

      if([mutableFetchResults count]!=0) 
      return [mutableFetchResults objectAtIndex:0]; 
      else { 
       return nil; 
      } 

     } 

but i am getting the following error: 

    2012-07-05 12:58:52.917 SpotLighter[963:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unimplemented SQL generation for predicate (Barcode LIKE[c] 1123)' 
    *** Call stack at first throw: 
    (
     0 CoreFoundation      0x01783be9 __exceptionPreprocess + 185 
     1 libobjc.A.dylib      0x018d85c2 objc_exception_throw + 47 
     2 CoreData       0x00fe4676 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 1270 
     3 CoreData       0x00f1ca78 -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 488 
     4 CoreData       0x00f1c881 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 49 
     5 CoreData       0x00f1c72e -[NSSQLCore newRowsForFetchPlan:] + 430 
     6 CoreData       0x00f1bab5 -[NSSQLCore objectsForFetchRequest:inContext:] + 357 
     7 CoreData       0x00f1b66e -[NSSQLCore executeRequest:withContext:error:] + 206 
     8 CoreData       0x00fcb0ec -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1084 
     9 CoreData       0x00f18807 -[NSManagedObjectContext executeFetchRequest:error:] + 359 
     10 SpotLighter       0x0000ff26 -[EntityCommands FetchManagedObject::] + 310 
     11 SpotLighter       0x0001436e -[WebAttendeeController FindAttendeeBy:] + 300 
     12 SpotLighter       0x0009aac6 -[MapBadge Map:::] + 4673 
     13 SpotLighter       0x000687d7 -[SpotLighterHomeScreen SpotLighterDataReceived::::] + 1111 
     14 SpotLighter       0x0002ca83 -[SpotlighterViewController txtNumericBadgeFieldDone:] + 445 
     15 UIKit        0x0051da6e -[UIApplication sendAction:to:from:forEvent:] + 119 
     16 UIKit        0x005ac1b5 -[UIControl sendAction:to:forEvent:] + 67 
     17 UIKit        0x005ae647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
     18 UIKit        0x005ad1f4 -[UIControl touchesEnded:withEvent:] + 458 
     19 UIKit        0x007a8987 _UIGestureRecognizerSortAndSendDelayedTouches + 3609 
     20 UIKit        0x007a90fc _UIGestureRecognizerUpdateObserver + 927 
     21 CoreFoundation      0x01764fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 
     22 CoreFoundation      0x016fa0e7 __CFRunLoopDoObservers + 295 
     23 CoreFoundation      0x016c2bd7 __CFRunLoopRun + 1575 
     24 CoreFoundation      0x016c2240 CFRunLoopRunSpecific + 208 
     25 CoreFoundation      0x016c2161 CFRunLoopRunInMode + 97 
     26 GraphicsServices     0x01f07268 GSEventRunModal + 217 
     27 GraphicsServices     0x01f0732d GSEventRun + 115 
     28 UIKit        0x0052c42e UIApplicationMain + 1160 
     29 SpotLighter       0x00002168 main + 102 
     30 SpotLighter       0x000020f9 start + 53 
    ) 
    terminate called after throwing an instance of 'NSException' 
+0

你有设置一个断点,并通过您的代码加强,以找到它的崩溃和检查正在通过变量的值?你还检查了什么?阅读文档?检查Apple的例子,比较他们在做什么和你在做什么? –

+0

好的谢谢。我会检查并让你知道应用程序崩溃的确切路线。 – Pallavi

回答

0
return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] %@",badgeID_ ]]; 

是给错误...

我更换了上述符合

return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] '%@'",badgeID_ ]]; 

它工作得很好!