nspredicate

NSSortDescriptor and NSPredicate for sorting and filtering

蓝咒 提交于 2019-12-08 09:39:37
问题 I have a tableView that has 5 different possible datasources depending on a flag object (NSNumber *)dataSourceAssignment . I've implemented an NSSortDescriptor that sorts dataSource by a (float)confidenceRating . After the datasource is assigned, I need to be able to filter the dataSource array by a (NSString *)genre . I understand how to use NSPredicate to filter my array, but I can't figure out how to do it efficiently when there are 5-6 different genre strings that could be checked. The

NSPredicate matching multiple properties

时光怂恿深爱的人放手 提交于 2019-12-08 08:12:54
问题 I've looked into filtering my data in my app and I got a recommendation to look at NSPredicate. I've been looking into it in one of hte Apress books, but I'm having a problem finding an example so I'm trying to create one. If I had something like this: myObject : NSObject @property (nonatomic, retain) NSString *firstName; @property (nonatomic, retain) NSString *lastName; @property (nonatomic, assign) NSInteger age; create some objects and put then into an array. Then I'm not sure how I would

How fetch objects with NSDate of today using NSPredicate?

大城市里の小女人 提交于 2019-12-08 08:00:01
问题 I'm stuck in a problem with my Core Data model and a fetch request that involves dates. I have some objects in a entity with a NSDate attribute; I need to extract the objects with the date of today but I always get nil from this code: public func getObjectsOfToday() -> Array<myObject>? { let entityDescription = NSEntityDescription.entityForName("Objects", inManagedObjectContext: DataAccess.sharedInstance.managedObjectContext) let request = NSFetchRequest() request.entity = entityDescription

Shorter way to write NSPredicate format string for testing multiple properties?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 06:56:47
问题 Is there a shorter way to write the format string for a predicate equivalent to this: [NSPredicate predicateWithFormat: @"key1 CONTAINS[cd] %@ OR key2 CONTAINS[cd] %@ OR key3 CONTAINS[cd] %@", searchString, searchString, searchString]; I have written a few predicate format strings like this, and I was thinking to simplify that by writing a method that takes an array of key paths and the search string to construct such a predicate. But I thought I’d ask if there is a built-in way to do this,

Find occurrence of substring in sentence only if word starts with substring

亡梦爱人 提交于 2019-12-08 06:46:21
问题 If I have 2 strings: "My name is Eric" "America is great" And my substring is 'eri'. How can I write a function that will only return true for the first sentence, because it has a WORD that starts with eri (Eric) and does not just contain eri (AmERIca). Note; I have been using NSPredicates, but using CONTAINS would return both, and using BEGINSWITH would only check the first word. This string is also contained in an Object, say and the property is called , so my current code is: NSPredicate

tableView:didSelectRowAtIndexPath: call to current-view Parser delegates

我的梦境 提交于 2019-12-08 04:44:53
问题 I have some pretty interesting logic going, basically I have this data which I want to check over before I display the next view.. just in case the data is empty I want to pop the view, if the data is not empty then I want to load the the view to display it onto the navigational stack. so in my tableView:didSelectRowAtIndexPath: method, when the selection is made I, get the current selection ID number so I can restrict the values of the data Im going to parse to only related values. This is

NSPredicate comparing transformed CLPlacemark with another CLPlacemark

末鹿安然 提交于 2019-12-08 04:02:45
问题 I'm saving CLPlacemark in Core data using NSValueTransformer . (so it's saved as NSData ) However I've come to a point where I need to filter the saved objects based on another CLPlacemark object. I've tried this, it doesn't work: NSExpression *exprPath = [NSExpression expressionForKeyPath:@"placemark"]; NSExpression *exprKeyword = [NSExpression expressionForConstantValue:[NSKeyedArchiver archivedDataWithRootObject:placemark]]; NSPredicate *predicate = [NSComparisonPredicate

NSPredicate not working with calculated field

寵の児 提交于 2019-12-08 02:17:15
问题 I have a Core Data project and am having difficulty searching the data with a simple calculated field and have no idea why it's not working. I have a Tutor entity, with core data string attributes "tutorFirstName" and "tutorLastName". I've created an additional string attribute "tutorFullName" which is populated in a Category as such: NSString *fullName = [@[self.tutorFirstName, self.tutorLastName] componentsJoinedByString:@" "]; The data is populated fine, but when I perform the following

NSPredicate with sub array

和自甴很熟 提交于 2019-12-07 23:38:21
问题 I am looking at the following type of data structure: { author = "Author 1"; channelIds = ( 7 ); }, { author = "Author 2"; channelIds = ( 7, 1 ); }, , { author = "Author 3"; channelIds = ( 3, 7 ); } I'd like to build an array consisting of all items where channeldIds = 7 . I was trying things along the lines of the following predicate: NSPredicate * filterById = [NSPredicate predicateWithFormat:@"channelIds[0] = '7'"]; How can I do what I'd like here? I can have an x number of channelIds, is

NSPredicate with regex to check alphanumeric

风格不统一 提交于 2019-12-07 17:35:17
问题 I want to check string with regex in Objective c. My code NSString *regexAmazonOrder =@"[a-zA-Z0-9]*"; NSPredicate *predicateAmazonOrder = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regexAmazonOrder]; if([predicateAmazonOrder evaluateWithObject:cardNumber.text]) { NSLog(@"Its coming inside AMAZON ORDER EVALUATIONS"); ... } But its not working. Help me out. I know its simple but eating my mind!!! Thanks 回答1: Try like this: (Untested, just to give you an starter) NSError *error = NULL;