最佳答案
我使用 NSUSerDefault 来存储用户首选项。我记得在什么地方读到过,把键设置为常量是个好主意——我也同意。下面是我目前的代码:
[[NSUserDefaults standardUserDefaults]
setObject:[NSNumber numberWithInt:polygon.numberOfSides]
forKey:@"polygonNumberOfSides"];
我试着改成:
@implementation Controller
NSString const *kPolygonNumberOfSides = @"polygonNumberOfSides";
-(void)savePolygonInfo {
[[NSUserDefaults standardUserDefaults]
setObject:[NSNumber numberWithInt:polygon.numberOfSides]
forKey:kPolygonNumberOfSides];
}
虽然这样做的工作,它产生“ warning: passing argument 1 of 'objectForKey:' discards qualifiers from pointer target type
”。我希望我的代码不受编译器警告的影响。我如何修正这个警告?