core-data

Any tips or best practices for adding a new item to a history while maintaining a maximum total number of items?

I'm working on some basic logging/history functionality for a Core Data iPhone app. I want to maintain a maximum number of history items. My general plan is to ignore the maximum when adding a new item and enforce it whenever I need to fetch all the items anyway (e.g. for searching or browsing the history). Alternatively, I could do it ...

How can I encrypt CoreData contents on an iPhone

I have some information I'd like to store statically encrypted on an iPhone application. I'm new to iPhone development, some I'm not terribly familiar with CoreData and how it integrates with the views. I have the data as JSON, though I can easily put it into a SQLITE3 database or any other backing data format. I'll take whatever is easi...

How can I maintain display order in UITableView using Core Data?

Hi All, I'm having some trouble getting my Core Data entities to play nice and order when using an UITableView. I've been through a number of tutorials and other questions here on StackOverflow, but there doesn't seem to be a clear or elegant way to do this - I'm really hoping I'm missing something. I have a single Core Data entity tha...

Approaches to save some NSManagedObjects but not others?

Hi folks, I'm working on a Core Data iPhone app that pulls remote resources from the web into NSManagedObjects and saves them locally. I want the user to be able to designate which of these objects should be saved. This means that some will be saved, but many should be deleted. However, I might want to save and delete at different time...

Core Data: migrating entities with self-referential properties

My Core Data model contains an entity, Shape, that has two self-referential relationships, which means four properties. One pair is a one-to-many relationship (Shape.containedBy <->> Shape.contains) and the another is a many-to-many relationship (Shape.nextShapes <<->> Shape.previousShapes). It all works perfectly in the application, so ...

Document Based App with Core Data vs plain Core Data app?

I am trying to understand the key differences between these two types of Core Data application templates. My understanding is that with a document based core data app you get access to NSDocument instances and a lot of document based behaviors for free (save dialogs, undo, etc). Assuming I want to create an application that is more "Pr...

New to Core Data for iphone

I am new to the iphone platform and am creating an app that retrievals a rss feed and displays it in a UITableView. I have gotten this working perfectly (or rather, the way I wanted). What I was thinking was I would store the current feed items on the phone so that it would initally load the old items it has stored while it got the new f...

Xcode setup for joint Mac & iPhone apps that share a model

I'm working on a Core Data application. I'd like to create interfaces on both the Mac and on iPhone, with both sharing the same model code. Is it possible to set up an Xcode project to have both OS X (x86_64 10.6) and iPhone targets? Or is there a better way to do this? ...

Customized initializers and read only properties in Core Data

Before working with Objective-C and Core Data, I had occasions to create classes that needed to be initialized with certain parameters that, after initialization, could not be modified (though they could be read). With Core Data, I believe I can create a customized init on my NSManagedObject derived class as long as it includes a way to...

Predicate to sum child's value

I'm trying to get total salary for the whole company by: NSNumber *totalSalary = [company valueForKeyPath:@"[email protected]"]; But I keep getting this error, "-[__NSSet0 decimalValue]: unrecognized selector sent to instance 0x10031eb00". I think I'm doing something wrong but I'm not sure where. ...

Fetch data by date range using Interface Builder

I have an NSTableView that is done using the typical IB and data bindings. It works well. However I need to put in a Segmented Control to indicate date range. So for example, if user clicks on the "Last Year" segmented control button, the table should only display records for last year. I looked at the data binding options in IB for th...

How do I model a selected entity instance from a set of possible instances in Core Data?

I have two Core Data entities, say Account and House. Each account can have a list of houses and a house can only be in one account, so that's a regular one-to-many relationship with an inverse. An account also has a "primary" property that indicates which of the many possible houses is primary or is nil if there are none. The identity ...

Updating Value in Core Data

Hi all, I'm trying to write a simple stock check program, and I have a Table View binded to Core Data. The table has 3 columns: Model, Price and Quantity In Stock. I have a NSTextField and a NSButton underneath this, so that the user can enter the quantity they wish to buy, and when they click "add to cart", the program should fetch the...

How would an iTunes-style Source-List be implemented with Bindings+CoreData in Cocoa?

Let's say, for illustration, I was writing an iTunes clone app in Cocoa, that was backed by CoreData. For simplification's sake, let's say there are two "sections", "Library" with things like Music, Movies, Radio, etc. And a second section called "Playlists" which holds user-generated playlists (just dumb lists, not smart playlists). So...

iPhone UITableView and CoreData conventions

Hi folks, I've got a question on the conventional way to structure something similar to the following: I have a screen which has a single line of data followed by a list of other data - and so I thought using a grouped UITableView with a single row'd section for the top and the rest in the section below would work well. As I'm using C...

How do I use NSTreeController, NSOutlineView and Core Data with an "invisible" root item?

I have a Core Data model which consists of a simple tree of a particular entity, which has two relationships, parent and children. I have an NSTreeController managing the model, with an NSOutlineView bound to the NSTreeController. My problem is that I need a single root object, but this should not display in the outline view, only its c...

NSManagedObject setValue problem (Core Data)

Hi, I wish to edit an existing record in core data. At the moment, I have this code, but it creates a new record (and inserts the correct data into the correct column): NSManagedObjectContext * context = [[NSApp delegate] managedObjectContext]; NSManagedObject * instrument = nil; instrument = [NSEntityDescription insertNewObj...

Limit the returned resultset in CoreData

In CoreData, if I want to limit the returned resultset to 100, is it enough to just set the fetch limit to 100, or do I need to set the fetch batch size to 100 as well? ...

Am I permitted to change the object graph in NSManagedObjectContextObjectsDidChangeNotification?

I'd like to know when an object has been inserted into my Core Data MOC and when it has, add it to another object with a relationship. So I watch the NSManagedObjectContextObjectsDidChangeNotification notifications find all the objects of the correct class in the set of inserted objects and make the connection using addObject so that t...

How to make CoreData return only rows that have a relationship?

I want my fetchRequest to only return rows that have a relationship that's not nil, but I am having problem forming the predicate for this. How should this be done? [Update] I should mention, the relationship is to-many. ...