我正在尝试尽可能地优化我的应用程序,您能否建议哪种方法最好,并推荐。
@implementation Methode1
+(BOOL)Isdone{
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:@"DEVICE_TYPE"];
if(!result){
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"DEVICE_TYPE"];
}
return result;
}
@end
@implementation Methode2
NSString * const deviceTypeKey @"DEVICE_TYPE";
+(BOOL)Isdone{
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:deviceTypeKey];
if(!result){
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:deviceTypeKey];
}
return result;
}
@end
@implementation Methode3
#define deviceTypeKey @"DEVICE_TYPE"
+(BOOL)Isdone{
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:deviceTypeKey];
if(!result){
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:deviceTypeKey];
}
return result;
}
@end
在上述三种方法中,哪一种最节省内存,为什么?