core-data

Instance variables of custom classes in NSManagedObject subclass

I have written a class Foo, and would like to include a Foo object as a property for an NSManagedObject subclass. Is this possible? Can Core Data store information other than strings, booleans, integers, etc.? ...

Tips for converting an iPhone 2.x app to 3.0 with Core Data

I have an app developed for iPhone OS 2.x. For the obvious reasons, the model classes in that app were written without Core Data. Now that 3.x is available, I'd like to know what are some of my options for taking my existing model classes and rebuilding them with Core Data. I do many things with my models besides the obvious, such as s...

Adding attribute to entity in Core Data

I've created all of my Managed Objects after mapping out all entities/attributes/relationships in the data model. Now I have the problem of needing to add additional attributes/relationships I haven't thought of when I first designed one of my entities/classes. Is there a way to modify my existing NSManagedObject class with Core Data sho...

different entity types in a single fetchedResultsController?

I have a UITableView which displays two different entity types -- each row could be either EntityA or EntityB. cellForRowAtIndexPath looks at the class type and determines how to create the cell. I am persisting my objects using Core Data and would like to use a fetchedResultsController to manage this tableview because of the memory-man...

NSPredicate with Conjuction

How to use NSPredicate for matching multiple conditions? I have a query Select * from Entity where name = "Sony" and type ="cd"; How i can give this "and" in NSPredicate... Please help.... ...

core data fetch results

With the below code I'm creating a fetch request. The problem I'm having is getting the fetch request data and doing something with it like putting it into a variable (like I'm trying to do below with the firstManagedObject variable). I.e., I don't understand what to do with my "result" NSArray that I've created (shown in below code) t...

Core Data - Hoping for errors, getting exceptions

Hi, I am developing an iPhone app using Core Data and ahev noticed that I get exceptions when I would expect and error, this is an example: NSError *error; // exception here if edited attribute name todoText in modeller and generated new database with that new name in it(ie clearing the iphone), ie tring to access a field not in the d...

Handling errors and exceptions on the iPhone

I am developinga Core Data app for the iPhone, and I am new to the whole platform etc. My question is, how much should I look for and handle errors and exceptions, for example when opening up the persistent store. Looking at the "Locations" Core Data Tutorial for example (hope its OK to quote it here like this): (Se comments in the cod...

Model instantiation question when using Core Data

I'm slightly confused in one aspect of Core Data. That is, when do I use the rudimentary alloc/init routine vs created an object with core data and saving it into the current managed object context. I know that's a rather vague question, so let me give you an example. I have an application I'm currently working on that iterates through...

Why does Core Data create NSManagedObject's with properties but no accompanying instance variable?

Exactly as the title says, why does Core Data create instances of NSManagedObject with properties for each entity's attribute, but no accompanying instance variable? The problem is, I would like to use some of my 'Entities' in a typical alloc/init style fashion in some parts of my code. Not using Core Data's fetching/context to create/st...

Store specific interactions with Core Data

I was reading the docs on core data looking to speed up my search. I found the following and was slightly confused as to what it meant: The SQL store, on the other hand, compiles the predicate and sort descriptors to SQL and evaluates the result in the database itself. This is done primarily for performance—databases are mu...

Core Data Sorting on a Calculated field

Hi, I am using iPhone OS 3.0 Core Data and the NSFetchedTResultsController. All is great except i have an issue with sorting the data. I have an event object that has a start date, it also has a relationship to another event. How can i sort the events based on the start date or the start date on the related event. What is the best...

Iphone Core Data crashing on Save

Hi, I'm currently writing an Iphone application using Core Data and I get a EXC_BAD_ACCESS error during the [managedObjectContext save:&&error] code line. This crash only happens after I modify certain fields. More specifically my entity has two string fields (out of about 10 fields), that get their values from a the return of a modal vi...

How to store dates without times in Core Data

I've been trying to find a sensible way of storing daily data using Core Data on the iPhone. My app receives data in csv format, with a date but no time: date, cycles 2009-08-01, 123 2009-08-02, 234 2009-08-03, 345 2009-08-04, 456 When this data is stored, there should only be one record per day. I figured the best thing to do was cr...

Adding unique objects to Core Data

I'm working on an iPhone app that gets a number of objects from a database. I'd like to store these using Core Data, but I'm having problems with my relationships. A Detail contains any number of POIs (points of interest). When I fetch a set of POI's from the server, they contain a detail ID. In order to associate the POI with the Detai...

Undo Management with Core Data

I'm trying to implement undo support using Core Data on the iPhone and I ran into a few problems. I currently have a couple of managed objects set up but when I make changes to their properties, these changes don't get recorded by the undo manager. From my understanding, Core Data is supposed to have this automatically set up and I shou...

Notify changes in property for Core Data?

The user will be able to add or change some value (property in my model with Core Data) in one view, when the user switch to another view, I want to show the newly added/changed value with an animation. Is there a way to get a notification that there has been a change or an update for a property with Core Data? ...

Recalculate attribute on every change of another attribute in Core Data MO.

I have an attribute in a Core Data Managed Object that I'm trying to update dependent on another attribute. How can I implement a method that is called every time the original attribute is changed? awakeFromInsert and awakeFromFetch obviously won't work. I've seen keyPathsForValuesAffectingValueForKey but I don't really understand how ...

Debugging NSObjectInaccessibleException - The NSManagedObject with ID:0x123456789 has been invalidated

I have a bug I'm struggling to track down. I believe what's happening is that I'm deleting an object from the underlying database whilst another managed object context (in another thread) has a fault on it and gets the 'NSObjectInaccessibleException' when it tries to fulfil the fault. The scenario is that I have a view accessing the dat...

Cocoa Core Data to PHP: Converting date

I have dates that are being stored in a database by core data. I then am using php to print out this date information but the date is coming out wrong. When I store Aug 2, 2009 in core data it comes out in the php as Fri, August 4, 1978. How do I fix the conversion? ...