ios - 用于电子邮件问题的 NSPredicate predicateWithFormat

标签 ios core-data nspredicate nsfetchrequest predicatewithformat

我在使用 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];
}

谁能解释一下,问题是什么?

最佳答案

在您的用户表中,字段名称 Email 必须是字符串。 enter image description here

 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/

相关文章:

ios - .sqlite 和 .storedata 有什么区别

ios - UITextField 中的文本向下移动并闪烁?

ios - iPhone 应用程序 - 使用预先填充的数据库还是依赖网络服务?

iphone - ios中的过滤器数组检查多个属性

ios - 在 Objective-C 中使用 NSPredicate 过滤自定义数据类的数组

ios - Swift 对象数组过滤

objective-c - 在objective-c中覆盖setter

ios - 使用swift制作下拉列表?

swift - addPersistentStoreWithType 到底在做什么?

ios - iCloud + 核心数据 : First import and user's feeling of loss of data