nsfetchrequest

Core Data: Returning properties depending on a value

Hi! can anyone guide me how to create a fetch request that will query an entity and returns any properties that qualify my criteria. Here's what I have. I have an entity that has 35 properties, all are in types of float. What I need was to see all properties of the entity which values was <= zero. I know how to return the values of the...

disordered/ordered context fetching

Hello to everyone, I cannot understanding why values assign to array objects become "disordered" after executing executeFetchRequest. Well, I'm not certain that fetching is the problem here. Here's the code. objects=[NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",nil]; NSManagedObject *DB = nil; for (int i=0;i<[objects count];i+...

CoreData: Find minimum of calculated property

Say I have a CoreData entity "Point" with two properties x and y (both NSNumber). How would a NSPredicate need to look like to let me find the closest Point to say a,b? for distance = sqrt((x-a)(x-a)+(y-b)(y-b)) While I could define a transient property that calculates a distance to a predefined point I can't see how I could programma...

NSDictionaryResultType expression not taking into account newly inserted objects

Hi there, I want the maximum value of a field in core data so I have set up the following request: // Create fetch NSFetchRequest *fetch = [[NSFetchRequest alloc] init]; [fetch setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]]; [fetch setResultType:NSDictionaryResultType]; // Expression for Max ...

Display data from NSArray in NSTableView

Hi all, I have a problem, and I reckon there's a really straightforward solution to it, but I can't fathom it out! I have this piece of code: NSManagedObjectContext * context = [[NSApp delegate] managedObjectContext]; NSManagedObjectModel * model = [[NSApp delegate] managedObjectModel]; NSDictionary * entities ...

cocoa iphone core-data predicate one-to-many fetchrequest

I have a set of data where one of the attributes (Firmware) is a one-to-many relationship. If I want to get any records where the firmware id is 1 I can create a predicate using @"(ANY Firmware.FID==1)" Then I have another set of conditions that will refine the set even more using (TopLevel==YES) AND (Parent>0) How can I combine t...

iPhone Core Data - Simple Query

Hello I am trying to create a Core Data iPhone application. One of the entities I'm tracking is cars, and one attribute of each car is "manufacturer". In the "edit car" section of my application, I have a UIPickerView that needs to be loaded with each of the unique manufacturers that have previously been entered into the system. What...

Fetching relations with Core Data

Hi, I have two managed objects which have a bidirectional relationship. It is a 'segmentWithDetails' which contains a 'segment' object. I use NSEntityDescription *entity = [NSEntityDescription entityForName:@"SegmentWithDetails" inManagedObjectContext:connectionDetailsService.connectionDetai...

Core Data pattern: how to efficiently update local info with changes from network?

I have some inefficiency in my app that I'd like to understand and fix. My algorithm is: fetch object collection from network for each object: if (corresponding locally stored object not found): -- A create object if (a nested related object locally not found): -- B create a related object I am doing the checking on l...

iPhone Fetch Request with localized sorting

I'm trying to get sorted localized data from a core data model. My code: NSEntityDescription *entityDescription = [NSEntityDescription entityForName: entityDescriptionValue inManagedObjectContext: context]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest s...

How to make an NSFetchRequest which asks for objects that have a specific firstname?

For example, I have a Managed Object Model with an Entity called "Friends", and a friend has a firstName. I want to get all friends where the firstName is equal to "George". How can I do that? ...

NSFetchRequests returns 0 results when it should return 1

Hi, I am trying to perform a fetch on core data after i insert an entity, and I get 0 results. I have a Person Entity.And i built a fetch Request in the DataModule GUI with the predicate: name == "PERSONNAME" Just before searching for the name i insert and save it first. and i know that works because i display the names in a table...

Core Data Automatic Update Inquery

I have a question concerning Core Data and how, if at all, Entities get updated automatically. Basically, let's say I fetch some data X. X has an inverse to-many relationship with Y. Then a method get's called to update an attribute in X. Does one have to fetch the data again? or will X automatically get the updated data? If this is no...

Performing multiple fetches in Core Data within the same view

I have my CD store setup and everything is working. Once my initial fetch is performed, I need to perform several fetches based on calculations using the data from my first fetch. The examples provided from Apple are great, and helped me get everything going but I'm struggling with executing successive fetches. Any suggestions, or tutori...

NSFetchRequest returns correct number of objects, but each object contains nil attributes

Hi, I can't figure out why this is happening. I can add to the context. But when I retrieve the objects, it returns the correct number of objects but the attributes of the objects are null. I am adding 3 instances with this code: +(BOOL)addStoreWithID:(NSNumber *)ID Latitude:(NSNumber *)latitude Longitude:(NSNumber *)longitude Name:(N...

Core Data - NSPredicate to filter to-many relationship

I have 2 entities, Task and List. Each task has a to-one relationship to a List object called "list", and there is an inverse relationship with List, which has a to-many relationship with Task called "tasks". I'm trying to use a fetch request with an NSPredicate to get all the Task objects that belong to a specified List: NSPredicate ...

NSFetchedResultsController fetch request - updating predicate and UITableView

In my iPhone Core Data app I have it configured in a master-detail view setup. The master view is a UITableView that lists objects of the List entity. The List entity has a to-many relationship with the Task entity (called "tasks"), and the Task entity has an inverse to-one relationship with List called "list". When a List object is se...

iphone, get the object count without performing a fetch?

Hi, I seem to recall that it's possible to return the resulting object count from an NSPredicate in CoreData without actually performing a fetch, but I can't find any reference to this. Can someone confirm that I wasn't dreaming (sad dream to have!), and would this be safe to do in another thread? Thanks Andy ...

iPhone Development - Query related records using CoreData

I have a case where i have three entities with one-to-many and one-to-many relationships: Entity A (Entity B relationhip), Entity B (Entity A relationship, Entity C relationship), Entity C (Entity B relationhip) I have the reference of Entity A, and now i want to fetch all the related Entity C records. How can i do that? (with least ...

iPhone NSCFString leaks in fetchRequest

In the following code: - (NSMutableArray *) fetchNotesForGroup: (NSString *)groupName { // Variables declaration NSMutableArray *result; NSFetchRequest *fetchRequest; NSEntityDescription *entity; NSSortDescriptor *sortDescriptor; NSPredicate *searchPredicate; NSError *error = nil; // Creates the fetchRequest and executes it f...