nspredicate

NSPredicate to filter between two dates of NSString type

一个人想着一个人 提交于 2019-12-05 03:43:51
问题 I've some data (as NSDictionary in an NSMutableArray ), a sample data is like, Consider each row as NSDictionary and entire table is an NSMutableArray contains events. I want to result between two dates, so I'm using NSPredicate to filter my data. Here's my code snippet for this, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Date >= %@ AND Date <= %@", startDate,endDate]; NSArray *filter = [arrayEvents filteredArrayUsingPredicate:predicate]; Test filtration : Case 1: NSString

NSPredicate Core Data

☆樱花仙子☆ 提交于 2019-12-05 02:58:09
问题 What is the exact difference between LIKE [c]%@ and = [c]%@ in core data NSPredicate ? I want to search for a string that should exactly match the receiver. Example : NSArray *arrayNames = [context fetchObjectsForEntityName:NSStringFromClass([PatientFamilyMember class]) withSortColumn:nil withSortDescending:FALSE withPredicate:@"patientID = %@ && firstName=[c]%@ && relationship=[c]%@ && lastName=[c]%@", self.pfm.patientID, firstName, relationship, lastName]; This works but I have not

Swift - Combining Predicates

ⅰ亾dé卋堺 提交于 2019-12-05 01:50:23
Is there a way of combining predicates in Swift? For example: let predicate1 = NSPredicate("self.label = 'foo'")) let predicate2 = NSPredicate("self.label = 'bar'")) let combinedPredicate = NSPredicate("self.staticTexts.elementMatchingPredicate(%@).exists AND self.staticTexts.elementMatchingPredicate(%@).exists", predicate1, predicate2) That gives me an error saying predicates cannot be arguments to other predicates. Is there another way to combine them? Glorfindel You'll need NSCompoundPredicate : let predicate1 = NSPredicate(format: "self.label = 'foo'", argumentArray: []) let predicate2 =

NSPredicate IN query from array elements

非 Y 不嫁゛ 提交于 2019-12-05 00:45:50
Apologies for a quirky title. I have an array of Ints and I would like to define an NSPredicate that will filter out items with connectionType equals to a value contained in the array. So basically something like: fetchRequest.predicate = NSPredicate(format: "connectionType IN { all items in array } I've found some Objective C examples that I think deals with this, but I just got into iOS development and have only worked with Swift, so some help here would be greatly appreciated :) I tried doing this: fetchRequest.predicate = NSPredicate(format: "connectionType IN \(myIntArray)" However, this

How to limit the result count of NSFetchRequest?

ε祈祈猫儿з 提交于 2019-12-04 22:19:14
I want to have a feature of "Recent 20 Items" in my iOS app. I use Core Data and NSFetchRequest . How can I limit the result number to 20 to achieve this? Thank you in advance! Kai. set the fetchLimit of the NSFetchRequest [request setFetchLimit:20]; Swift 3.0 uses: request.fetchLimit = 20 来源: https://stackoverflow.com/questions/5000927/how-to-limit-the-result-count-of-nsfetchrequest

NSPredicate find object with attribute in NSSet

拟墨画扇 提交于 2019-12-04 22:09:48
问题 I have an NSMangedObject that contains NSSet of other NSManagedObjects . I need to check if these objects has an value in NSSet and then return them. I use MagicalRecord for fetching data. So I need something like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringObjects contains %@", string]; So if NSSet stringObjects contains some string that I am looking for so then return object I have requested. One note here: stringObjects (name just for example it represent my

NSDictionary Predicate filter on child objects

夙愿已清 提交于 2019-12-04 21:54:30
I'm trying to filter a response from Facebook's API, the JSON looks like this: { "Data": [ { "first_name" : "Joe", "last_name" : "bloggs", "uuid" : "123" }, { "first_name" : "johnny", "last_name" : "appleseed", "uuid" : "321" } ] } I load this into a NSDictionary, accessing it like [[friendDictionary objectForKey:@"data"] allObjects] I'm now trying to filter based on the first_name and last_name based on when someone inputs a name into a textfield. Here's what I have but its failing horribly: NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"ANY.first_name

Core Data- predicate with dates

僤鯓⒐⒋嵵緔 提交于 2019-12-04 18:21:04
问题 I'm stumped trying to write a predicate for "Recently Completed" tasks, i.e. show the task if it was completed within the last 7 days. I think I need to do something like this: "if NOW < dateCompleted + 7 days". The dateCompleted is an attribute on the table, but I'm not sure how I'm supposed to get it's value and add 7 days to it from within the predicate. I guess I need to fetch the attribute value first before writing the NSPredicate, but how? I don't have access to the managedObject at

Returning a list of directories with NSMetadataQuery and NSPredicate

你。 提交于 2019-12-04 17:37:40
I'm trying to get a list of directories in the user's iCloud folder. I worked out how to look for special types of files (such as txt files) and it works fine: NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; _query = query; //Search all files in the Documents directories of the application’s iCloud container directories: [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey]; [query setPredicate:pred]; [query startQuery]; However, I'm now trying to

IOS NSPredicate 查询、搜索

隐身守侯 提交于 2019-12-04 17:33:16
简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取。 最常用到的函数 + (NSPredicate *)predicateWithFormat:(NSString *)predicateFormat, ...; 1.比较运算符 > 、< 、== 、 >= 、<= 、 != 例:@"number >= 99" 2.范围运算符:IN 、BETWEEN 例:@"number BETWEEN {1,5}" @"address IN {'shanghai','nanjing'}" 3.字符串本身:SELF 例:@"SELF == 'APPLE'" 4.字符串相关:BEGINSWITH、ENDSWITH、CONTAINS 例:@"name CONTAIN[cd] 'ang'" //包含某个字符串 @"name BEGINSWITH[c] 'sh'" //以某个字符串开头 @"name ENDSWITH[d] 'ang'" //以某个字符串结束 注:[c]不区分大小写 , [d]不区分发音符号即没有重音符号 , [cd]既不区分大小写,也不区分发音符号。 5.通配符:LIKE 例:@"name LIKE[cd] '*er*'" //*代表通配符,Like也接受[cd]. @"name LIKE[cd] '???er*'" 6