nspredicate

Dynamic searching in tableview in iOS

假装没事ソ 提交于 2019-12-07 11:58:44
问题 I've a tableview and text field where I've implemented search method. Right now, when I write some value in textfield and click search button, then it search in the tableview . But, I want it to be dynamic means the moment I start typing in textfield it should start searching without clicking any button . How can I do this? 回答1: Just Connect this method on Editing Changed Event of your TextField . So, this method is called when you are changing its value. - (IBAction)txtValueChanged:

Parsing and changing NSPredicate

喜你入骨 提交于 2019-12-07 10:18:41
问题 I have to migrate data from a previous app version to a new version. This also affects some predicates ( NSPredicate instances) that were saved by users, which means that I have to change them programmatically. Currently I try to parse the string I get with [NSPredicate predicateFormat] and change some expressions manually. For instance oldKeyPath == "something" to newKeyPath == "something" . But it feels like a hack and I'm curious if there is a better way? I read Apple's documentations

Subclassing NSPredicate to add operator

核能气质少年 提交于 2019-12-07 05:53:50
问题 Cocoa defines predicate classes ( NSPredicate , NSExpression , etc.) which "provide a general means of specifying queries in Cocoa" Predicate Programming . This set of classes describes what I need but with one little short-coming : I'd like additional operators. NSComparisonPredicate already handles 14 operators (NSPredicateOperatorType) but I would like to add, say, temporal operators... or operators to represent things such as: " variable has at least n entries " (binary operator) "

A reverse kind of string compare using NSPredicate

最后都变了- 提交于 2019-12-07 04:07:16
问题 I've been searching for this answer all over internet but so far no luck. So I need to consult the smart and nice people here. This is my first time asking a question here, so I hope I am doing this right and not repeating the question. For all the examples I saw, it's the search string that is a substring of what's stored in the Core Data. On the other hand, I want to achieve the following: The strings stored in core data are actually sub-strings. I want to do a search by getting all core

Why “NOT IN” does not work in this NSPredicate?

心不动则不痛 提交于 2019-12-07 00:45:17
问题 A . b and B . a are inverse to-many relationships. Why does this predicate for A work: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", bObject.a]; while this one does not: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT %@ IN b", bObject]; I think both predicates should give the same result — the collection of A s that have no relation with bObject via a<-->b . But in fact, the first one gives the correct collection while the second one not. Update

iOS 正则表达式判断UITextField是否为全汉字,全字母,全数字,数字和字母

这一生的挚爱 提交于 2019-12-07 00:43:55
判断全汉字(这个问题苦恼了我很久,现在很方便,几行代码就搞定): if ([ self deptNameInputShouldChinese ]) { [ DemonAlertHelper showToastWithMessage : @" 只能是中文 " ]; return ; } 调用这个方法就可 #pragma mark-- #pragma mark 输入中文 - ( BOOL ) deptNameInputShouldChinese { NSString *regex = @"[\u4e00-\u9fa5]+" ; NSPredicate *pred = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,regex]; if (![pred evaluateWithObject : inputTextField . text ]) { return YES ; } return NO ; } 判断全数字: - ( BOOL ) deptNumInputShouldNumber { NSString *regex = @"[0-9]*" ; NSPredicate *pred = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,regex]; if (

Swift - Combining Predicates

对着背影说爱祢 提交于 2019-12-06 20:42:54
问题 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? 回答1: You'll need NSCompoundPredicate:

NSPredicate IN query from array elements

穿精又带淫゛_ 提交于 2019-12-06 20:14:16
问题 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

to check an coredata object is nil

纵然是瞬间 提交于 2019-12-06 17:56:26
问题 I want to find out the objects in the core data, my code: Types: signedDate (Date) alarmDate (Date) starTime (NSDate) endTime (NSDate) NSString *str = @"(signedDate >= %@) AND (signedDate < %@) AND (alarmDate == nil)"; NSPredicate *predicate = [NSPredicate predicateWithFormat:str, starTime, endTime]; [request setPredicate:predicate]; NSArray *results=[context executeFetchRequest:request error:nil]; predicate is wrong ? How to judge an coredata object is nil? What the predicate should be? 回答1:

How to limit the result count of NSFetchRequest?

帅比萌擦擦* 提交于 2019-12-06 16:41:57
问题 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. 回答1: set the fetchLimit of the NSFetchRequest [request setFetchLimit:20]; 回答2: Swift 3.0 uses: request.fetchLimit = 20 来源: https://stackoverflow.com/questions/5000927/how-to-limit-the-result-count-of-nsfetchrequest