19.3 Undefinierte Schlüssel

Unsere Anwendung hat ein grundsätzliches Problem. Zwar soll der Benutzer author oder title in das erste Textfeld eingeben, doch er kann eingeben, was er will. Probieren Sie es, geben Sie asdf in das erste Textfeld ein.

image with no caption

Der Benutzer erhält keinerlei Feedback. Er weiß nicht, dass er etwas falschgemacht hat. Wir als Entwickler sehen andererseits Folgendes in der Debugger-Konsole:

Exception detected while handling key input.
[<PragBook 0x1001068f0> valueForUndefinedKey:]:
        this class is not key value coding-compliant for the key asdf.

Um das zu beheben, muss unser PragBook die Methode valueForUndefined-Key: implementieren. In ...

Get Cocoa-Programmierung now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.