nspredicate

How to specify range with NSPredicate in Objective C

久未见 提交于 2019-12-22 08:57:13
问题 I want to query sqllite table by specifying a range. So it's like give me all records whose id column between 3000 and 3010. I tried what Apple recommends, but it didn't work. Here is what I tried and failed. NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]]; I have 2 strings called start and end. I updated Apple's example as following. NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"%@ BETWEEN %@", columnName, @

Forcing the display of a compound row with NSPredicateEditor

安稳与你 提交于 2019-12-22 06:57:04
问题 I'm creating an NSPredicateEditor in code and trying to achieve what I had hoped would be a fairly simple task. Basically, I would like to display a compound NSPredicateEditorRowTemplate (giving the user the option to perform matches when "All/Any/None of the following are true") and a number of fairly basic subrows beneath it. To do this, I construct my NSPredicateEditor and bind its value in order to save changes as the user edits their predicate. The issue I'm experiencing is that, no

Core Data Performance: NSPredicate comparing objects

匆匆过客 提交于 2019-12-22 04:17:21
问题 If my Author NSManagedObject model has a authorID attribute (determined by the server), will an NSFetchRequest perform better if the NSPredicate filters by authorID rather than the complete Author object? Let's say I'm fetching all Book NSManagedObject s by a certain author . Which predicateFormat is better? [NSPredicate predicateWithFormat:@"author = %@", anAuthor] or [NSPredicate predicateWithFormat:@"author.authorID = %@", anAuthor.authorID] What's the best way to profile this? I have Core

NSDictionary Predicate filter on child objects

徘徊边缘 提交于 2019-12-22 00:32:44
问题 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:

CoreData - NSPredicate with NSSet

南楼画角 提交于 2019-12-21 22:24:54
问题 I have a DB with the following relationships: A <<-->> B A: Members table; B: Activities table A Member has many Activities, and each Activity has many Members. So, a many to many relationship. When the user selects an Activity from a tableView, a new tableView should be pushed with all the Members that has that Activity. In the NSPredicate of the "child" tableView, I do: request.entity = [NSEntityDescription entityForName:@"Members" inManagedObjectContext:context]; request.predicate =

Updating fetchedResultsController for predicate set by UISearchBar

▼魔方 西西 提交于 2019-12-21 20:59:01
问题 Refactored to vanilla UIViewController Rather than having the UITableView toggle between active and inactive UISearchController , I refactored to a vanilla UIViewController with a UISearchBar at the top and a UITableView directly underneath it. What I'm trying to do is toggle the fetchedResultsController between having a predicate which is set by the text in the searchBar and one that grabs everything. I found this answer, which describes a solution to a similar problem in Objective-C and

most effective way of searching using NSPredicate OR statement

烈酒焚心 提交于 2019-12-21 20:23:30
问题 I tried to build a predicate in a previous post, but ended up doing it this way because after 3 hours, I couldn't get it to work. I feel like there has to be a more effective way, also I need the predicates to be case insensitive. 10,000 cars I have a tire, wheel, seat as three car parts I want to find all cars that have a tire. THEN I want to find all cars that have a wheel. THEN I want to find all cars that have a seat. (I know many will be duplicates, but that's what I need) Please let me

How to use sortDescriptor for an attribute on a to many relationship

ぃ、小莉子 提交于 2019-12-21 18:57:34
问题 I have a Song Entity and a Playlist Entity. Playlist can have multiple Songs and Songs can be linked to multiple Playlist. I have a ListToSongs Entity which maintains the order in which Songs were added to the Playlist. I am not using "Ordered Relationship" in ios5 (I am aware of its existence and I need more control over my model) and I store the order by a "sortOrder" field in PlayListToSong entity. So the schema is modeled as (relationship names are written in parentheses below): Song

Swift Core Data Predicate IN Clause

青春壹個敷衍的年華 提交于 2019-12-21 14:09:32
问题 I'm attempting to use an IN clause with an NSPredicate. I'm getting the following error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa000000000000611' Here's the code: let fetchRequest: NSFetchRequest<Employee> = NSFetchRequest(entityName: "Employee") fetchRequest.sortDescriptors = [ NSSortDescriptor.init(key: "lastName", ascending: true) ]

Using NSDate within an NSPredicate

送分小仙女□ 提交于 2019-12-21 12:49:14
问题 Is there a particular way to configure an NSPredicate to compare dates? Essentially I have a Photo object that has an NSDate, lastViewed. I'd like to configure an NSPredicate that will return all the Photo objects that have been viewed more recently than a specified time period - typically two days. I'm obtaining the past date like so: NSTimeInterval secondsPast = -172800; NSDate * twoDaysPast = [NSDate dateWithTimeInterval:secondsPast sinceDate:[NSDate date]]; And configuring the NSPredicate