0

I am finding the closest location to my current location and I'd like to NSLog the closest CLLocation variable name instead of it's value.

How would I go about doing this? This is how I get the value of the longitude and latitude of the variable:

NSLog(@"the closest location is %@", closestLocation);

For example, I would want it to say: "the closest location is Starbucks (the variable name)" instead of "the closest location is LONGITUDE, LATITUDE".

  • http://stackoverflow.com/questions/2818542/print-out-the-variable-name-objective-c – Saikat Jul 29 '13 at 01:29
  • @Saikat Checked that out. I believe that has a different purpose. Can you explain it with my code? – user2628653 Jul 29 '13 at 01:32
  • 1
    The purpose seems exactly the same to me. You want to NSLog the variable name right? That's what the code in the link does. – borrrden Jul 29 '13 at 01:38
  • @borrrden As a beginner, I do not understand. Will you explain? How would I do that with my code? – user2628653 Jul 29 '13 at 01:42
  • @user the question is a bit confusing now to me. Do you want the name of a place given it's lat/lng? If so, checkout http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html – Saikat Jul 29 '13 at 01:45
  • @Saikat yes. Just to print out the variable name. – user2628653 Jul 29 '13 at 01:48

1 Answers1

1

The comments are spot on, but since you don't see the connection I'll try to make it clear:

#define LogTheLocationVariable(x) NSLog(@"The variable is %s", #x)

Now you can use the macro:

LogTheLocationVariable(closestLocation);

And you'll get:

The variable is closestLocation
Caleb
  • 124,013
  • 19
  • 183
  • 272