I am a real n00b in developing iOS app. This is my first application in my life and I really need some helps.
My app concept is running workout.
-
When user click button ‘start run’, app will track a distance which inform users how far do they run in another view.
-
Next, when the user click button ‘Finish workout’, the distance will be added(plused) to the ‘total distance’ variable which need to be saved all the time when finishing each run trip.
-
Moreover, ‘total distance’ must load when app starts in index view.
As I mentioned, I am a beginner so that could anybody please tell me how to do? where should I put the code and how? I will appreciate sample code as well. I need to know how could I plus the new(fresh) data with saved data and how to save and show it.
Really sorry for my English.
Thank you in your advance support.
====EDITED==================
Here is my code in calculating distance function.
-(void)computeDistanceFrom:(CLLocation *)oldL tO:(CLLocation *)newL {
NSLog(@"oldd %@",oldL);
NSLog(@"new %@",newL);
CLLocationDistance currentDistance = [oldL distanceFromLocation:newL];
NSLog(@"you have travel=%f",currentDistance);
distance = distance + currentDistance;
double distanceInKm = distance/1000;
distanceLabelValue = [[NSString stringWithFormat:@"%1.2f",distanceInKm]retain];
distanceLabel.text = distanceLabelValue;
}
Now I can get distance which user workouts each time. But I dunt know how and where to create ‘total distance’ variable. Then plus the workout distance to ‘total distance’. And Finally save ‘total distance’ and show it in the index view.
please help…
Use NSUserDefaults to save your data.
For saving your data, for example ‘1.25’:
For retrieving your data: