Search code examples
binaryxcode4.2

Xcode creates binaries based on old states of project


Xcode (4.2.1) creates binaries based on old states of the project. For example: I declared and used the property "myProperty" in the past. But later I deleted this property and deleted all the code that used that property. When I build and run the App crashes, saying "MyClass is not key value coding-compliant for the key myProperty". Similar things appeared in the past, not just with code. I replaced an image file in my project with another image with the same name. In the project's folder, there was definetely the new image file. However, after build and run it still displayed the old image. What I've already tried: Just Build, then run; close and reopen project; close and restart Xcode; restart Mac. Any suggestions?

Sorry. The property still existed as references in the xib. That was the problem.


Solution

  • Just to clarify: This is probably one of the most frequently asked questions! When you see "MyClass is not key value coding-compliant for the key myProperty" on launch, that is a hint to you that you have an outlet with the name "myProperty" in your nib file. Okay, it's not a very good error message, but you just have to learn that that's what it means. It means that because when the app launches and the nib loads and the nib loading mechanism tries to match that name with a real instance variable or accessors in the living instance, using key value coding, it doesn't find it and you get that crash and that message.

    Sometimes this happens because you formed the outlet and then later changed your code.

    Sometimes it happens because the owner object is the wrong class, as in This class is not a key value coding-compliant or What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"

    (If you really really really think Xcode is creating a binary based on the old state of the project, clean the target completely in accordance with my instructions here: How to Empty Caches and Clean All Targets Xcode 4)