1

I have a problem.

I have an NSObjectController called "mapController" and I want to put some defaults when the object is created. I do this inside the windowControllerDidLoadNib method of my document, as suggested by the docs. But…

if (![mapController content]){   // No map defined yet.
    [mapController add: self];   // This should create the instance.

    NSLog(@"%@",[mapController content]); // Gives NULL.

I tried:

    BOOL ok = [mapController fetchWithRequest:nil merge:NO error:nil];
    NSLog(@"%@",[mapController content]); // Gives NULL.

The content of mapController is in the Core Data "scratch pad" but I can't access it. I have to set one of its attributes like this:

    [[mapController content] setValue:[matrix colorReference] forKey:@"mapData"];

This gives no error, the file is marked as changed, but it I test the value:

    NSLog(@"%@",[mapController content]); // Gives NULL.

When the heck it the controller's content really HERE? Something appears on the screen but… what actually? Reading the docs doesn't help me…

berfis
  • 417
  • 4
  • 17

2 Answers2

1

OK, I found the answer in the docs:

add: Creates a new object and sets it as the receiver’s content object.

Discussion

Creates a new object of the appropriate entity (specified by entityName) or class (specified by objectClass)—see newObject—and sets it as the receiver’s content object using addObject:.

Special Considerations

Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.

That's why

[[mapController content] setValue:[matrix colorReference] forKey:@"mapData"];

worked fine when called elsewhere in the app. It was a few iterations later…

Well… maybe this post will save you a couple of hours you could use to sleep longer.

Regards,

Bernard

berfis
  • 417
  • 4
  • 17
0

I don't think its your mapController, I think it is your NSLog. Try this:

NSLog(@"%@", mapController);

also try getting simple data from the content, like the float value of the CGColorRef so you can use other formatters like %f.

I would have tested this but I cannot seem to create an instance of NSObjectController because it is an undeclared identifier. What framework is it defined in? Did you have to #import anything?

WolfLink
  • 3,308
  • 2
  • 26
  • 44