Richard Fuhr
Richard Fuhr

Reputation: 3565

In Xcode Document App: Why would init method of MyDocument be called twice?

I followed Chapter 8 of Hillegass to implement the RaiseMan application there. Then I decided to follow the same process to implement the code for an exercise in a Cocoa programming class that I am taking, but I got the following very cryptic error message after building and running.

Cannot create BOOL from object <_NSControllerObjectProxy: 0x100460e30> of class _NSControllerObjectProxy

I have no idea what this error message means. Doing a Google search brought up some hits, but their remedies seemed to be to do things that I was already doing.

I stared at all the connections and assignments that I made in Interface Builder and nothing looks obviously wrong.

So I went into the debugger and set a breakpoint inside the init method of the MyDocument class and it is being called twice. How could that happen? What should I be looking for that would make the init method be called twice? The stack trace shows that init is called by system functions that we did not write ourselves.

For comparison, I went back to the project that follows Chapter 8 of Hillegass and set a breakpoint inside the init method of the MyDocument class, and it is being called once ( which is what one would expect ).

Upvotes: 2

Views: 1529

Answers (2)

Rajiv
Rajiv

Reputation: 11

I just ran into this myself. And then I remembered seeing something odd before, whose significance hadn't struck me at the time. Which is that in my XIB file, there was a "My Document" object, in addition to the "File's Owner" object (which is what actually represents the document in the XIB file). I have no idea how it got there, but I deleted it in IB, recompiled, and presto, [MyDocument init] only gets called once now.

Upvotes: 1

Peter Hosey
Peter Hosey

Reputation: 96323

Cannot create BOOL from object <_NSControllerObjectProxy: 0x100460e30> of class _NSControllerObjectProxy

It appears you've bound a BOOL property to a controller, and not specified a model key path. Most probably, you bound one of the Cocoa view classes' built-in bindings, such as enabled or editable.

Look through your nib for views whose enabled or editable you've bound, and make sure they are all bound to the correct model key path.

Upvotes: 6

Related Questions