A: 

There are many ways to do this. The quick and dirty way (and some will frown upon it) is to just declare those as globals in this file and use extern to access them from other files.

Better is to make those @properties of the class, and provide a getter so you can access those from another class or part of the app. That does assume that this class will be available for other classes to access later on.

You also can use delegate to get information. And...

Thinking a bit more, I would probably store data like this someplace else, and will use this routine to update the value in that location (by using a setter of that class), so this method here would just get the location and then store it elsewhere.

You might want to read Scott Knaster's book on Objective C and Mac development for a primer on Obj C.

mahboudz
thanks for the hints. i did try setting the locLat and locLong variables as properties, and this allows me to compile my code but it results in a runtime exception. im not yet even sure how to setup the variables as globals! aside from the book you mention are there any other more concise tutorials you could recommend?
bbb
Globals in Obj C are the same as C. I can't say whether the runtime exceptions are from this or something else. I'd need more info. Try Apple's site for Obj C tutorials, but they won't help much if you don't know C.
mahboudz
@bbb - the runtime exception is (probably) because the strings you create are autoreleased. send a retain message to them (and remember to release them in your dealloc).
Roger Nolan
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html#//apple_ref/doc/uid/TP30001163-CH1-SW2
mahboudz
+1  A: 

Here's how I recommend doing it:

Store lat/long in a dictionary and fire them off as strings bundled in a notification. Setup an observer in the application delegate and have the callback function store the lat/long in class properties of the application delegate and/or store them in the application defaults.

In your class where you acquire the coordinates:

- (void)locationUpdate:(CLLocation *)location {
    NSString *locationString, *locLat, *locLong;
    locationString = [location description];
    locLat  = [NSString stringWithFormat:@"%lf", location.coordinate.latitude];
    locLong = [NSString stringWithFormat:@"%lf", location.coordinate.longitude];
    NSDictionary *locationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:locationString, @"description", 
        locLat, @"latitude", locLong, @"longitude", nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"updateSearchLocation" 
        object:self userInfo:locationDictionary];
}

In your application delegate class:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Listen for search coordinates broadcast
    [[NSNotificationCenter defaultCenter] addObserver:self
       selector:@selector(setCoordinates:)
   name:@"updateSearchLocation" object:nil];
}

    - (void)setCoordinates:(id)sender {
        self.latitude = [[sender userInfo] objectForKey:@"latitude"];
        self.longitude = [[sender userInfo] objectForKey:@"longitude"];
        NSLog(@"location = %@", [[sender userInfo] objectForKey:@"description"]);

    }

Dont forget to setup the class properties in the application delegate header file as NSString. You can then access the coordinates by calling directly from the application delegate:

YourAppDelegateClassName *appDelegate = [[UIApplication sharedApplication] delegate];
NSLog(@"lat = %@, long = %@", appDelegate.latitude, appDelegate.longitude);

Or you can access them anywhere from the user defaults:

[[NSUserDefaults standardUserDefaults] objectForKey:@"latitude"];
[[NSUserDefaults standardUserDefaults] objectForKey:@"longitude"];

I hope that helps.

Stone