1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Problem with NSUserDefaults

Discussion in 'iPhone/iPad Programming' started by icinnamon, Aug 24, 2008.

  1. macrumors newbie

    I have this code in one method:
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:longitude forKey:@"longitude"];
            [defaults setObject:latitude forKey:@"latitude"];
            [defaults synchronize];
            directionsText.text = latitude;
    And then I have this to access the user defaults:
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            double oldLon = [[defaults objectForKey:@"longitude"] doubleValue];
            double oldLat = [[defaults objectForKey:@"latitude"] doubleValue];
            courseText.text = [NSString stringWithFormat:@"%@",oldLat];
    When I run this second section of code, the program crashes (both on the simulator and iPhone!)! Is there some user configuration step that I'm missing?

  2. Moderator


    Staff Member

    What types are the objects longitude and latitude in the first section of code?

Share This Page