Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer is yes. @Caleb points to the right resources, but getting it to work is still quite awkward. I thought I'd place a resumé here:</p> <p>For two <code>NSPersistentStore</code> instances to share the same model, you have to add a configuration to your model, which is a string-named subset of the entities: </p> <p><img src="https://i.stack.imgur.com/2P3GH.png" alt="Model configurations"></p> <p>In the model, to an entity that belongs to the second store, you add a fetched property (<code>NSFetchedPropertyDescription</code> for googlability). This is somewhat of a very simple stored procedure, and it could look like this: </p> <p><img src="https://i.stack.imgur.com/kohbO.png" alt="NSPredicate format for the fetched property"></p> <p>Then, when you add the stores to your persistent store coordinator, you use the strings for the <code>configuration</code> argument (more <a href="https://developer.apple.com/LIBRARY/IOS/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSPersistentStoreCoordinator_Class/NSPersistentStoreCoordinator.html#//apple_ref/doc/constant_group/Store_Options" rel="noreferrer">info about the options here</a>):</p> <pre><code>[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"ModifyInBackground" URL:storeURL1 options:options error:&amp;error] [persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"ModifyInMain" URL:storeURL2 options:options error:&amp;error] </code></pre> <p>Finally, when you want to get from the entity in store B to the entity in store A, you trigger the fetched property like you would trigger a fault, just by accessing it. </p> <p><strong>Note:</strong> A fetched property always returns an NSArray, because the predicate you write to establish the link might have multiple results. If you want to get to just one entity, you could place something like this in a wrapper method of your <code>NSManagedObject</code> subclass:</p> <pre><code>Wallpaper *recordedWallpaper = [record.wallpaper lastObject]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload