core-data

Decide which caching startegy to use ?

Hi all, I want to cache my loaded data so that I can reduce my application start time . I know several strategies to store application data i.e. core data, nsuserdefaults , archiving . Now my scenario is that suppose that I have array of maximum 10 objects each object having 5 fields . So I can not decide which strategy to store th...

What's the difference between -objectRegisteredForID: and -existingObjectWithID:objectIDerror: ?

What's the difference between getting an managed object with - (NSManagedObject *)objectRegisteredForID:(NSManagedObjectID *)objectID and - (NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectIDerror:(NSError **)error Are there different types of NSManagedObjectID? Is there a difference between a "registered ID" and...

Must I explicitely enable exceptions in Xcode?

-objectWithID: is supposed to give me an object that's broken when the ID doesn't exist. The documentation says, that this object throws an exception when I try to access an property. However, it never throws any. Must I enable exceptions so that they're really thrown? Here's some code: // Assume: a new managed object has been created...

How to use ManagedObjectID the right way?

What I'm trying is this: 1) Create a new manged object 2) Get it's temporary id with [myMO objectID]; 3) Convert that ID to an NSURL, so I can save it for future reference: NSManagedObjectID *moID = [myMO objectID]; NSURL *url = [moID URIRepresentation]; 4) Save the managed object context 5) Some time later, fetch that object usi...

Will calling -obtainPermanentIDsForObjects:error: cause new managed objects to be stored?

Example: I create a bunch of new NSManagedObject instances. Not stored yet, but already added to a managed object context. Then I want permanent IDs so I can refer back to those objects 10 years later. At this point, will these objects be actually saved to the persistent store? I guess they have to - but I'm not sure how Core Data obtai...

How does Core Data obtain permanent IDs from the persistent store?

Is there an explanation how this is done? Is Core Data creating dummy records to get IDs for not-yet-saved managed objects? ...

Is it still true that it's a bad idea to name attributes and relationships like any non-parameter method of NSObject or NSManagedObject?

I did some little experimentation on this. I created an boolean attribute, named isFault. You know, that's a method of NSManagedObject and therefore actually not allowed for an attribute name because of KVC. Simply, I used the default Core Data template for this test, but created the data model programmatically so I can show you what ...

What can I do with an Transformable attribute type in Core Data on the iPhone?

There's this Transformable data type for attributes. What is it good for? Are there good examples? I'd like to play around with this. So after searching a while I came across this: NSValueTransformer. Seems to be something I need for this. So how would I get started with this? For example, if I wanted to store an UIColor object, would ...

Is it true that I don't have to create my own NSValueTransformer subclass if my object applies to the NSCoding protocol?

i.e. lets say I want to store a custom data type in Core Data. The documentation claims that the default NSValueTransformer is an NSKeyedUnarchiveFromDataTransformer thing, so I guess if the class of the object I want to store conforms already to that NSCoding protocol, I don't need to bother about making a custom NSValueTransformer? Is ...

Core Data Cross-Store Relationship with Fetched Properties

In my Core Data model (on iPhone SDK 3.1) I have several entities that are associated with the same instance of an image. The image itself is also stored as managed object. In order to save disk space, I'm trying to create 1 db file for the images and another db file for all other objects. Reading Apple's documentation and googling for ...

What kind of category is this and where's the implementation?

The data modeler generated this class for me: @interface Cat : NSManagedObject { } @property (nonatomic, retain) NSSet* event; @end @interface Cat (CoreDataGeneratedAccessors) - (void)addEventObject:(NSManagedObject *)value; - (void)removeEventObject:(NSManagedObject *)value; - (void)addEvent:(NSSet *)value; - (void)removeEvent:(...

Iphone - managedobjectcontext not properly saving

Any idea why //should save the object context. NSError *error; if (![managedObjectContext save:&error]) { NSLog(@"SAVE ERROR"); } when implemented in a view controller(accessed via a drill down tableview) won't properly save the information? I am passing the moc from the beginning (rootview hands off to tableview, tableview r...

In which situations would I want to call -processPendingChanges of NSManagedObjectContext?

In which situations would I want to call -processPendingChanges of NSManagedObjectContext? ...

Core Data - Fetch Related Records

Hi all, I have a Core Data object called Car that has a one-to-many relationship with another Core Data object called Claims (i.e., one Car has many Claims). I've created the entities in the data model editor, and am able to list, edit, and work with the Car objects. What I can't figure out is this: given a Car, how to get an array of...

Model-Controller cyclic reference/design problem

I have a CoreData entity X, and controllers for this entity, XController. Now there's another entity, XGroup, containing a collection of X entities, and a XGroupController. Now the problem is that XGroupController needs to interact with XController, and it would be nice to just pass XGroupController a XGroup to observe, and then get th...

What's the point of setRetainsRegisteredObjects: ?

Why would I want to set that to YES? What difference would that make? Must I worry about this? ...

In which situations would I want to call -rollback in Core Data?

I try to grok this method. Is that only useful when I'm dealing with undo/redo operations? Or can I use that in general, when I have changed my object graph after saving it and then decide that that was a bad idea? So -rollback would go back to the last saved state of my object graph? ...

How to discard references to any managed objects fetched using the receiver?

The documentation for the -reset method of NSManagedObjectContext is confusing... All the receiver's managed objects are “forgotten.” If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards. So what does that mean? ...

What does -setPropagatesDeletesAtEndOfEvent: actually do?

Let me try it: If I don't set this, then the default value is YES. So when I delete an managed object from the context, the context propagates this immediately to the persistent store so the object is gone? And when I set this to NO, then objects are deleted from the persistent store only when calling -save? Is that really true? I mean...

What's the staleness interval good for?

When an managed object is fetched, and the staleness interval is set to 5 minutes, what happens after 10 minutes, when I access an property of that object? Would Core Data then perform a fresh fetch request? Does that make sense? I can't think of a situation where data is already cached but the object is a fault. When can this happen? ...