Tag: nspredicate

如何用NSPredicate过滤数组来组合单词

[filteredArray filterUsingPredicate: [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] %@", searchText]]; filteredArray包含简单的NSString。 [你好,我的,得到,七,等等]; 它会给所有以searchText开头的string。 但是,如果string将是“我的名字是”和searchText = name的单词的组合。 NSPredicate将如何实现这一目标? 更新:如何,如果我想结果searchText = name ,但不searchText = ame ? 也许这样: [filteredArray filterUsingPredicate: [NSPredicate predicateWithFormat: @"self BEGINSWITH[cd] %@ or self CONTENTS[cd] %@", searchText, searchText]]; 但是,它应该首先显示以searchText开始的string,并且仅在包含searchText的string之后显示。

如何在Objective C中使用NSPredicate指定范围

我想通过指定一个范围来查询sqllite表。 所以就像给我所有logging的列号在3000到3010之间。 我尝试了苹果的build议,但没有奏效。 这是我尝试和失败。 NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]]; 我有2个string叫做开始和结束。 我更新了苹果的例子如下。 NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"%@ BETWEEN %@", columnName, @[start,end]]; 当我用上面的谓词executeFetchRequest时,即使表中有匹配谓词的logging,我也会得到0条logging。 有人能指出我出错的地方吗?

使用NSPredicate进行反向string比较

我一直在寻找这个答案在互联网上,但迄今没有运气。 所以我需要咨询这里的聪明人和好人。 这是我第一次在这里问一个问题,所以我希望我这样做是正确的,而不是重复这个问题。 对于我所看到的所有示例,searchstring是存储在Core Data中的子string。 另一方面,我想达到以下目的: 存储在核心数据中的string实际上是子string。 我想通过获取所有具有属于所提供的searchstring的子string的核心数据行来进行search。 例如:在核心数据中,我有“AB”,“BC”,“ABC”,“ABCDEF”,“GH”,“ABA”在应用程序中,通过提供超级​​string“ABCDEF” ,结果将返回“AB”,“BC”,“ABC”,“ABCDEF”而不是“GH”,“ABA”,因为这两个子串不属于超级串。 我应该如何设置我的predicateWithFormat语句? 这不会'工作因为它正在做相反的: NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"substring LIKE[c] %@", @"ABCDEF"]; 谢谢大家!

NSPredicate无法parsing格式string

我看不到这些代码行有任何问题。 为什么不能parsing? [NSPredicate predicateWithFormat:@"(username CONTAINS[cd] %1$@) || " "(userId CONTAINS[cd] %1$@) || " "(firstname CONTAINS[cd] %1$@) || " "(lastname CONTAINS[cd] %1$@)", searchString]" 日志也没有帮助。 终止由于未捕获的exception'NSInvalidArgumentException'的应用程序,原因:'无法parsing格式string'(用户名CONTAINS [cd]%1 $ @)||(用户名CONTAINS [cd]%1 $ @)||(名字CONTAINS [ cd]%1 $ @)||(姓氏CONTAINS [cd]%1 $ @)“' 编辑1: 好的,看起来像predicateWithFormat不明白“%1 $ @”。 我把它切换到 [… predicateWithFormat:[NSString stringWithFormat:…]] // (same format as above) 它通过了线路。 但是,下一个问题是: self.filteredUserList = [self.userList […]

为什么“不在”在这个NSPredicate中不起作用?

A b和B a是相反的多关系。 为什么这个A工作的谓词: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", bObject.a]; 而这一个不: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT %@ IN b", bObject]; 我认为两个谓词应该给出相同的结果 – 通过a<–>b与bObject没有关系的A的集合。 但实际上,第一个是正确的收集,而第二个是不正确的收集。 更新: 这里是一个示例项目,其中A b由Account体现。 filtered_clients和B a由Client体现。 filtered_by 。 在MasterViewController.m切换143行和144行的注释以查看差异。 请帮我find我的代码中的错误,或者确认它是一个Core Data错误,所以我可以报告给苹果。 非常感谢。

无法将“Date”传递给NSPredicate(格式:…)而没有“as CVarArg”

这是我应该如何传递一个Date到NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer) 。 let endDate = Date() NSPredicate(format: "endDate == %@", endDate as CVarArg) 它看起来有点笨拙,我怀疑我做错了什么。

如何限制NSFetchRequest的结果数量?

我想在我的iOS应用程序中具有“近20个项目”的function。 我使用核心数据和NSFetchRequest 。 我怎么能限制结果数到20来实现呢? 先谢谢你! 凯。

NSDictionary子对象的谓词filter

我试图过滤来自Facebook的API的响应,JSON看起来像这样: { "Data": [ { "first_name" : "Joe", "last_name" : "bloggs", "uuid" : "123" }, { "first_name" : "johnny", "last_name" : "appleseed", "uuid" : "321" } ] } 我加载到一个NSDictionary,访问它像[[friendDictionary objectForKey:@"data"] allObjects] 我现在试图基于first_name和last_name基于何时有人向文本字段中input名称进行过滤。 这是我所拥有的,但是它的可怕之处在于: NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"ANY.first_name beginswith[c] %@ OR ANY.last_name beginswith[c] %@", friendField.text, friendField.text]]; NSLog(@"%@", [[[friendDictionary objectForKey:@"data"] allObjects] filteredArrayUsingPredicate:filter]); 任何帮助非常感谢,谢谢你们

CoreData有条件地使用NSPredicate(swift)获取NSDate

基本上我有一个名为TimeLoc的实体,它有三个属性:时间,经度和纬度。 它们的types分别是Date,Double和Double。 当我尝试使用属性时间上的filter发出请求时,我卡住了。 这是我的代码: … var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate) var context: NSManagedObjectContext = self.managedObjectContext! var request = NSFetchRequest(entityName: "TimeLoc") var endTime = NSDate() var startTime = NSDate(timeIntervalSinceNow: -65) let predicate = NSPredicate(format: "time>= \(startTime) AND time<= \(endTime)") request.predicate = predicate var results: NSArray = context.executeFetchRequest(request, error: nil)! … 我得到了以下错误:“无法parsing格式string”时间> = 2015-07-14 03:24:03 […]

最有效的使用NSPredicate OR语句进行search的方法

我试图在之前的文章中构build一个谓词,但是最终这样做是因为3个小时之后,我无法完成这个工作。 我觉得必须有一个更有效的方法,我也需要谓词不区分大小写。 10,000辆我有一个轮胎,车轮,座位作为三个汽车部件,我想find所有有轮胎的汽车。 那么我想find所有有车轮的汽车。 那么我想find所有有座位的汽车。 (我知道许多将是重复的,但这就是我所需要的) 请让我知道是否有更有效的方法。 也请让我知道如何使谓词不区分大小写。 先谢谢你! -(NSArray*) loadCarsFromCoreData:(NSMutableArray*)inputCarParts{ NSMutableArray *totalResults=[[NSMutableArray alloc]init]; NSFetchRequest *fetchRequest =[[NSFetchRequest alloc]init]; //To find the cars we are using the car parts NSEntityDescription *entity = [NSEntityDescription entityForName:@"CarParts" inManagedObjectContext:[self managedObjectContext]]; [fetchRequest setEntity:entity]; NSError *error; NSMutableArray *predicates =[self parseCarPartsIntoAPredicateArray:inputCarParts]; for (int i=0; i<[predicates count]; i++) { [fetchRequest setPredicate:[predicates objectAtIndex:i]]; NSArray *records […]