gpt4 book ai didi

iphone - NSPredicate - 评估两个条件

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:25 24 4
gpt4 key购买 nike

我想知道如何使用 NSPredicate 评估满足两个条件的 NSString。例如,如何检查至少应包含一个大写字母和至少一个数字的字符串。

最佳答案

您可以对两个或多个条件使用 ANDing。

 NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entityDescription];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fbUID = %@ AND birthDate = %d AND birthMonth = %d AND greetingYear = %d", uID, birthDate, birthMonth, greetingYear];

//NSLog(@"%@ :",predicate);
[fetchRequest setPredicate:predicate];

NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

您可以在 NSPredicate 上查看更多信息 HERE .

关于iphone - NSPredicate - 评估两个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20487614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com