Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data: entity properties getting mixed
    primarykey
    data
    text
    <p>I have an <code>NSWindow</code> which I use to create new records. After pressing the Add button, a certain method is called in which I do the following:</p> <pre><code>- (IBAction)addActionAddSheet:sender { NSManagedObjectContext *moc = [self managedObjectContext]; NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:moc]; [newObject setValue:[newRecipeName stringValue] forKey:@"name"]; [newObject setValue:[newRecipeInstructions string] forKey:@"instructions"]; NSLog(@"New object is: %@", newObject); [NSApp endSheet:addSheet]; [addSheet orderOut:sender]; } </code></pre> <p>The (edited) output from <code>NSLog</code> after I have executed this twice, is as follows:</p> <pre><code>&lt;NSManagedObject: 0x10045c6a0&gt; (entity: Recipe; id: 0x1004564a0 &lt;x-coredata:///Recipe/t18FEC674-8937-49DF-A18B-940EF82E83C32&gt; ; data: { instructions = X; name = X; }) &lt;NSManagedObject: 0x1149069a0&gt; (entity: Recipe; id: 0x100106a20 &lt;x-coredata:///Recipe/t18FEC674-8937-49DF-A18B-940EF82E83C33&gt; ; data: { instructions = Y; name = Y; }) </code></pre> <p>This is completely as expected. However, my tableview, which is bound to an array controller, shows that both objects X and Y have <strong>X</strong> as value for <code>instructions</code>.</p> <p>When I exit my application and the data is saved, what I see in my xml file is again different:</p> <pre><code> &lt;attribute name="name" type="string"&gt;Y&lt;/attribute&gt; &lt;attribute name="instructions" type="string"&gt;Y&lt;/attribute&gt; &lt;attribute name="name" type="string"&gt;X&lt;/attribute&gt; &lt;attribute name="instructions" type="string"&gt;Y&lt;/attribute&gt; </code></pre> <p>This time they both have value <strong>Y</strong>.</p> <p>The output from <code>NSLog</code> does show that I'm dealing with two different objects here, so I'm not sure what I might be doing that could influence both.</p> <p>These are is my unedited output:</p> <pre><code>2009-12-07 14:46:18.409 Recipe[11578:a0f] managedObjectContext 2009-12-07 14:46:18.411 Recipe[11578:a0f] persistentStoreCoordinator 2009-12-07 14:46:18.411 Recipe[11578:a0f] managedObjectModel 2009-12-07 14:46:18.423 Recipe[11578:a0f] applicationSupportDirectory 2009-12-07 14:46:18.436 Recipe[11578:a0f] externalRecordsDirectory 2009-12-07 14:46:20.484 Recipe[11578:a0f] Show Add sheet 2009-12-07 14:46:20.485 Recipe[11578:a0f] Clear values 2009-12-07 14:46:20.494 Recipe[11578:a0f] call beginSheet 2009-12-07 14:46:23.632 Recipe[11578:a0f] addActionAddSheet: -- Add button clicked 2009-12-07 14:46:23.632 Recipe[11578:a0f] Create new mananged obj in context 2009-12-07 14:46:23.634 Recipe[11578:a0f] managedObjectContext 2009-12-07 14:46:23.635 Recipe[11578:a0f] Set values for name and instructions 2009-12-07 14:46:23.636 Recipe[11578:a0f] New object is: &lt;NSManagedObject: 0x1001c89c0&gt; (entity: Recipe; id: 0x1001c9470 &lt;x-coredata:///Recipe/tE9BD4EE3-082C-4715-AB66-2C3580223F9E2&gt; ; data: { instructions = A; name = A; }) 2009-12-07 14:46:23.636 Recipe[11578:a0f] call [NSApp endSheet:] and [addSheet orderOut:] 2009-12-07 14:46:23.637 Recipe[11578:a0f] addSheetDidEnd:returnCode:contextInfo: -- empty method 2009-12-07 14:46:35.327 Recipe[11578:a0f] Show Add sheet 2009-12-07 14:46:35.328 Recipe[11578:a0f] Clear values 2009-12-07 14:46:35.337 Recipe[11578:a0f] call beginSheet 2009-12-07 14:46:39.836 Recipe[11578:a0f] addActionAddSheet: -- Add button clicked 2009-12-07 14:46:39.836 Recipe[11578:a0f] Create new mananged obj in context 2009-12-07 14:46:39.838 Recipe[11578:a0f] managedObjectContext 2009-12-07 14:46:39.839 Recipe[11578:a0f] Set values for name and instructions 2009-12-07 14:46:39.843 Recipe[11578:a0f] New object is: &lt;NSManagedObject: 0x102070ad0&gt; (entity: Recipe; id: 0x10205e420 &lt;x-coredata:///Recipe/tE9BD4EE3-082C-4715-AB66-2C3580223F9E3&gt; ; data: { instructions = B; name = B; }) 2009-12-07 14:46:39.843 Recipe[11578:a0f] call [NSApp endSheet:] and [addSheet orderOut:] 2009-12-07 14:46:39.844 Recipe[11578:a0f] addSheetDidEnd:returnCode:contextInfo: -- empty method </code></pre> <p>Recipe A:</p> <p><a href="http://web.me.com/bpeiren/recipeA.png" rel="nofollow noreferrer">http://web.me.com/bpeiren/recipeA.png</a></p> <p>Recipe B:</p> <p><a href="http://web.me.com/bpeiren/recipeB.png" rel="nofollow noreferrer">http://web.me.com/bpeiren/recipeB.png</a></p> <p>My array controller:</p> <p><a href="http://web.me.com/bpeiren/Cocoa/so/array_controller.png" rel="nofollow noreferrer">http://web.me.com/bpeiren/Cocoa/so/array_controller.png</a></p> <p>My table column's bindings:</p> <p><a href="http://web.me.com/bpeiren/Cocoa/so/tablecolumn.png" rel="nofollow noreferrer">http://web.me.com/bpeiren/Cocoa/so/tablecolumn.png</a></p> <p>My label's binding:</p> <p><a href="http://web.me.com/bpeiren/Cocoa/so/label.png" rel="nofollow noreferrer">http://web.me.com/bpeiren/Cocoa/so/label.png</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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