1. 简单数据持久化
-(void)SavePersonData { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:[NSNumber numberWithInt:myMoney] forKey:@"money"]; [[NSUserDefaults standardUserDefaults] synchronize]; } -(void)ReadPersonData { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; int hasInitialized = [[ userDefault objectForKey:@"initialized"] intValue]; if(1 == hasInitialized) { myMoney = [[ userDefault objectForKey:@"money"] intValue]; } else { [userDefault setObject:[NSNumber numberWithInt:1] forKey:@"initialized"]; [[NSUserDefaults standardUserDefaults] synchronize]; } }
[self ReadPersonData];
[self SavePersonData];