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 days I came to the following conclusion: - Create 1 datamodel that contains the description of all entities - Use 1 persistent store coordinator
Use configurations to store image entities in a different file (sqlite) than the other entities (see here)
And, as Core Data does not support relationships from instances in one persistent store to instances in another persistent store, use "Fetched Properties" to create weak, one-way relationships
Using configurations is pretty straightforward: assign a configuration to the entity using the data modeler and declare which configuration to use when adding a persistent store to the coordinator. In my case, I added to stores to the coordinator.
But here's the problem: when fetching, let's say 'User' objects from one store, how do I use fetched properties to load the images associated with that user (and assign them to the user object)?
Do I have to write a custom accessor method for 'images' in the user object? How (and where) to specify the predicate for the fetched property?
I was convinced there must be a tutorial or example explaining this (as this obviously is the way Apple suggests to do it). But no luck so far.
Any idea?
Hopefully we can start a discussion on this topic. I'm sure there are other (more clever) ways to solve this...
Fetched Properties in Core Data are properties that return an array value from a predicate. A fetched property predicate is a Core Data query that evaluates to an array of results.
Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.
You can use . filter on the fetchedResults. Yes you can, but that's a Swift function. Using NSDelegate delegates filtering to Core Data which can be more efficient, especially on large data sets.
Using separate stores will not make anything "better" in this situation. Storing large binary data in Core Data is not recommended. You should store it on disk and use references to the file system.
See the BLOBs section here.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With