ios - calling void with NSUserDefaults -
i making simple ios game. game levels in void.
so when when level gets completed calling void code
[self levelthreevoid];
it works great. want save current void in nsuserdefaults
, call when app opened user.
please if know answer. making me insane.
edit
adding code comments easier reading.
-(void)yoluc{ self.oyunpicone.image = [uiimage imagenamed:nil]; self.oyunpictwo.image = [uiimage imagenamed:nil]; self.oyunpicthree.image = [uiimage imagenamed:nil]; self.oyunpicfour.image = [uiimage imagenamed:nil]; [herfbiroutlet settitle:@"" forstate:uicontrolstatenormal]; xaltext.text = [nsstring stringwithformat:@"%d",xal+50]; // qiziltext.text = [nsstring stringwithformat:@"%d",qizil+3]; }
to store variables of interests, write below code in "void" function:
nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setobject:value1 forkey:@"uniquekey1"]; [defaults setobject:value2 forkey:@"uniquekey2"]; [defaults synchronize];
to retrieve save data next time user logs app, can write below code in viewdidload/viewdidappear
method or method of choice gets called upon app launch:
nsuserdefaults *defaults; defaults = [nsuserdefaults standarduserdefaults]; value1 = [defaults objectforkey:@"uniquekey1"]; value2 = [defaults objectforkey:@"uniquekey2"];
note way values retrieved based on "uniquekey's". don't duplicate them across different variables. if want overwrite them, use same key once again. hope helps!
Comments
Post a Comment