nsfetchrequest

-[NSCFNumber count]: unrecognized selector

不想你离开。 提交于 2019-12-10 16:13:35
问题 I've got some Core Data code that follows Apple's sample code precisely (the Fetching Attribute Values that Satisfy a Given Function example). I'm using it to get the max value of a field, so I can then increment it when I insert the next object of that entity type. I couldn't get the code to work at all, until I switched my Store Type from NSXMLStoreType to NSSQLiteStoreType , then all of a sudden everything seemed to be working. However, that's not the case. I noticed that it would always

CoreData Predicate get every sentence that contains any word in array

此生再无相见时 提交于 2019-12-10 15:53:41
问题 In Swift 4 I have a CoreData "Sentence" model that has a String attribute "englishsentence". I also have an array of "words" and would like to fetch all sentences for which the "englishsentence" attribute contains one or more of the words in the array. var words = ["today", "yesterday", "tomorrow"] This array is just an example. It is supposed to change at runtime and can have any length. and in the fetch request I am trying to do something like this: let fetchRequest = NSFetchRequest

Showing duplicate cells in UITableView via NSFetchedResultsController?

孤者浪人 提交于 2019-12-10 12:19:30
问题 I am querying Core Data to find the "OLDEST" and "HEAVIEST" amongst a group of people. With a larger dataset this usually works (as the chance of a duplicate match is less), but with a small dataset where the OLDEST person may also be the HEAVIEST I am having problems. [John, 77, 160] [Pete, 56, 155] [Jane, 19, 130] [Fred, 27, 159] [Jill, 32, 128] As I want to display this information in 2 UITableViewCell s of a UITableView I am doing this by first running 2 NSFetchRequests (one to find the

NSPredicate that filters out subclass results

柔情痞子 提交于 2019-12-10 04:46:54
问题 I have two classes, Company and MyCompany. MyCompany is a subclass of Company, and Company is a subclass of NSManagedObject. I am trying to write a predicate for an NSFetchRequest that will return results of the class Company, but filter out MyCompany objects. I have tried the following (suggested from here https://stackoverflow.com/a/8065935/472344): NSPredicate *predicate = [NSPredicate predicateWithFormat:@"class != %@",NSStringFromClass([myCompany class])]; But I get an error: 'keypath

avoid duplicate results on Core Data fetch

落爺英雄遲暮 提交于 2019-12-09 13:51:07
问题 I have a subclass of the CoreDataTableViewController (subclass of UITAbleViewController dome by the people on Stanford done to link CoreData and TableViews). On this Class, I want to perform a fecth, sorting by an attribute called "definition" and the code which executes it is the following: - (void)setupFetchedResultsController{ NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:self.entity]; request.propertiesToFetch=[NSArray arrayWithObject:@"definition"]; request

fetch request for entity.attribute == @“somevalue”

◇◆丶佛笑我妖孽 提交于 2019-12-09 11:55:19
问题 How do I setup a fetch request to only pull the data from an entity's attribute with one particular value? This is the basic code I've used before. -(void)fetchResults { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:self.entityDescription.name]; NSString *cacheName = [self.entityDescription.name stringByAppendingString:@"Cache"]; // predicate code if (self.predicate != nil) { [fetchRequest setPredicate:self.predicate]; } // end of predicate code NSSortDescriptor

NSPredicate, get results with a subset of one-to-many relationship

十年热恋 提交于 2019-12-09 01:41:13
问题 I'mm working around with Core Data and NSFetchedResultsController . My Data Model looks like this: Product with one-to-many relationship called dataLines . The dataLine entity has a property name theWeek . I want to fetch all Product where dataLines.theWeek == someValue . This is easily done with a subquery. But this returns all dataLines. Is it possible to create a NSPredicate that returns the Product and a subset if dataLines only with the dataLines == someValue ? 回答1: What you want to

NSInvalidArgumentException', reason: 'Unknown predicate type for predicate: BLOCKPREDICATE(0x70ad750)' Error

陌路散爱 提交于 2019-12-08 15:50:40
问题 I have a core data database and I am trying to create a fetch request using a block predicate, but I get an Unknown Predicate error: NOTE: employeeToHouse is a property of type House that was created for me when I subclassed NSManagedObject NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Place"]; request.predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { Place *sortPlace = (Place *)evaluatedObject; CLLocation *placeLocation =

Swift Core Data - Group doesn't Work

坚强是说给别人听的谎言 提交于 2019-12-08 12:15:12
问题 I am working on a simple iOS Swift app and can't find any solution for a small problem with core data. I have to group some data which i fetch out of core data, but it doesn't work. This is my fetchRequest: <NSFetchRequest: 0x7f82fbe105e0> (entity: Sets; predicate: ((null)); sortDescriptors: (( "(sort, ascending, compare:)" )); type: NSDictionaryResultType; includesPendingChanges: NO; propertiesToFetch: (( name )); propertiesToGroupBy: (( name )); ) I have sort and added properties to group

Retrieve last row/object in Core Data entity as a string

走远了吗. 提交于 2019-12-08 09:14:30
问题 I need to develop a simple login system for my Questionnaire app. I have two Entity 's - one for saving Questionnaire data called NGLS which stores client details, survey answers, etc, and another called Admin for the user. The user can type in their username which gets saved to the Admin entity. They can then run through the Questionnaire as many times as they like, and each completed survey gets saved to the NGLS entity after every survey like so: // Save managedObject NSError *error; [