我的应用程序在启动时崩溃。请指点我。非常感激。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
NSDictionary *temp = @{@(0): NSStringFromCGPoint(CGPointZero),
@(1): NSStringFromCGPoint(CGPointZero),
@(2): NSStringFromCGPoint(CGPointZero),
@(3): NSStringFromCGPoint(CGPointZero),
};
// Pro
NSDictionary *defaults = @{ // ... other PrefKeys
// No crash if I comment out this line
GMListVCOffsetsPrefKey:temp,
};
[[NSUserDefaults standardUserDefaults] registerDefaults: defaults];
}
答案 0 :(得分:4)
plist中的键必须是字符串。这里有数字。
参见Property list documentation:“虽然NSDictionary和CFDictionary对象允许它们的键是任何类型的对象,但如果键不是字符串对象,则集合不是属性列表对象”。
答案 1 :(得分:2)
您正在使用非NSString键来导致崩溃的临时数组。下面的代码不会崩溃。
NSDictionary *temp = @{@"0": NSStringFromCGPoint(CGPointZero),
@"1": NSStringFromCGPoint(CGPointZero),
@"2": NSStringFromCGPoint(CGPointZero),
@"3": NSStringFromCGPoint(CGPointZero),
};
// Pro
NSDictionary *defaults = @{ // ... other PrefKeys
// No crash if I comment out this line
GMListVCOffsetsPrefKey:temp,
};
[[NSUserDefaults standardUserDefaults] registerDefaults: defaults];