私は現在、initが私のユーザーのデフォルトであるこの関数を持っています:
+ (void)initialize
{
// Create a dictionary to hold the default user preference values
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
// Put defaults in the dictionary
[defaultValues setObject:@(YES) forKey:@"pref key 1"];
... (further inits)
MyCStruct struct;
struct.width = struct.height = 0;
struct.frameDuration = struct.frameTimeScale = 0;
NSValue* structDefaultValue = [NSValue value:&struct
withObjCType:@encode(MyCStruct)];
[defaultValues setObject:structDefaultValue
forKey:@"myPrefKey"];
// Register the dictionary of defaults
[[NSUserDefaults standardUserDefaults] registerDefaults: defaultValues];
}
デフォルトの登録中に「CFRetain」で Obj-C 例外ブレークポイントを取得します。NSValue を使用する前はすべて問題なかったので、メモリに関連していると確信しています。構造体はローカル関数スタックで有効であることを知っているので、これが問題なのだろうか? NSValue は、ポインタを取得した値をコピーしますか?
ヒープ上に構造体を作成する必要がありますか?
ありがとう!