サンプルアプリを試作してホットキー設定画面を試作してみる。
まずこんなウィンドウを作る。
設定キーを文字列表現させたいので、モデル(NSUserDefaults)の値を加工するフォーマッタ HotkeyFormatter を用意する。
HotkeyFormatter.h
@interface HotkeyFormatter : NSFormatter {
}
@end
HotkeyFormatter.m
@implementation HotkeyFormatter
- (NSString *)stringForObjectValue:(id)anObject
{
NSString* key_desc = [anObject description];
return key_desc;
}
- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error
{
*anObject = string;
return YES;
}
@end
実装は後で行う。現在は動作確認用にメソッドだけ用意しておく。
これを InterfaceBuilder上でインスタンス化しておき、テキストボックスの Formatterアウトレットへ接続する。

こんな具合になる。

Cocoaバインディングを使い、入力した値を NSUserDefaults で管理させる。

実行して文字を入力するとそれがそのまま表示される。
入力した文字列はアプリを再起動すると復元される。

ベースができたので次回は NSUserDefaultsへ格納されたホットキーの値を表示させる処理を実装する。