Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data Object Injection (with Dependency) Storyboard
    text
    copied!<p>I'm trying to use segues for passing core data MOC and Entities to other View Controllers.</p> <p>So I'm using the prepareForSegue method and doing something like this</p> <pre><code>SecondViewController *svc = (SecondViewController *)[segue destinationViewController]; //passing the current managed object context to the other view controller svc.managedObjectContext = managedObjectContext </code></pre> <p>I then want the pass the currentEntity to the same view controller</p> <pre><code>//rootEntity is -- TheManagedObject * rootEntity in the second view controller svc.rootEntity = currentEntity </code></pre> <p>I'm not sure if the above svc.rootEntity is the right way to do it but it feels like the right way to do it to inject the currentEntity in the next view controller.</p> <p>In the Second View Controller I want to insert a new object for the entity based on the rootEntity injection above.</p> <p>I know I would normally create a new Managed Object by doing this:</p> <pre><code>NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:@"TheNewObject" in ManagedObjectContext:managedObjectContext //MOC injected from the First View Controller </code></pre> <p>My issue is that I want to do the above newObject but I want it to be dependent (relationship) to the first passed entity (the above rootEntity).</p> <p>I've come close but I keep getting unassociated NewObjects (should be one to many)</p> <p>The next step would the be to repeat the above and insert another level in the next view controller based on the the NewObject in the second view Controller. </p> <p>I've read Zarra's book and a few others but they all use init methods that don't seem to work with segues.</p> <p>Thanks,</p>
 

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