我在使用 predicateWithFormat 方法创建 NSPredicate 类型对象时遇到问题。
AppDelegate *appdelegateObj = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = [appdelegateObj managedObjectContext];
NSString *emailWithBackslashedAtTheRate = [email stringByReplacingOccurrencesOfString:@"@" withString:@"\\@"];
NSFetchRequest *fetchRequestObj = [NSFetchRequest fetchRequestWithEntityName:@"Usertable"];
NSMutableArray *dataList;
**NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"email CONTAINS[c] %@",emailWithBackslashedAtTheRate]];**
[fetchRequestObj setPredicate:predicate];
@synchronized(delegate.persistentStoreCoordinator) {
NSError *error = nil;
NSMutableArray *filteredUser = (NSMutableArray *)[self.managedObjectContext executeFetchRequest:fetchRequestObj error:&error];
}
谁能解释一下,问题是什么?
最佳答案
AppDelegate *coreAppDelegate=[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context=[coreAppDelegate managedObjectContext];
NSEntityDescription *entityDecs=[NSEntityDescription entityForName:@"UserDetail" inManagedObjectContext:context];
NSFetchRequest *request =[[NSFetchRequest alloc]init];
[request setEntity:entityDecs];
// NSLog(@"username = %@",mutarr);
NSPredicate *pred=[NSPredicate predicateWithFormat:@"(email=%@)",TxtEmail];
[request setPredicate:pred];
NSManagedObject *matches =nil;
NSError *error;
关于ios - 用于电子邮件问题的 NSPredicate predicateWithFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34524200/