Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:32:23+00:00 2026-06-17T08:32:23+00:00

I’m try to localize a start and end point to an address string, so

  • 0

I’m try to localize a start and end point to an address string, so that I can store it into NSUserDefaults. The problem is that the method continues executing and does not set my variable.

NSLog(@"Begin");

__block NSString *returnAddress = @"";

[self.geoCoder reverseGeocodeLocation:self.locManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
    if(error){
        NSLog(@"%@", [error localizedDescription]);
    }

    CLPlacemark *placemark = [placemarks lastObject];

    startAddressString = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                          placemark.subThoroughfare, placemark.thoroughfare,
                          placemark.postalCode, placemark.locality,
                          placemark.administrativeArea,
                          placemark.country];
    returnAddress = startAddressString;

    //[self.view setUserInteractionEnabled:YES];
}];
NSLog(returnAddress);

NSLog(@"Einde");

This is what my application debugger shows:

start
einde

If for example the address of my location is : “Mainstreet 32, CITY”. Then what i would want to see is the following:

Start
Mainstreet 32, CITY
Einde

The problem is that my code does not wait for my CLGeocoder to finish, so my variable returnAddress is not set when it is returned, and it is empty.

Does anyone know how to work around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:32:24+00:00Added an answer on June 17, 2026 at 8:32 am

    Because reverseGeocodeLocation has a completion block, it is handed off to another thread when execution reaches it – but execution on the main thread will still continue onto the next operation, which is NSLog(returnAddress). At this point, returnAddress hasn’t been set yet because reverseGeocodeLocation was JUST handed off to the other thread.

    When working with completion blocks, you’ll have to start thinking about working asynchronously.

    Consider leaving reverseGeocodeLocation as the last operation in your method, and then calling a new method with the remainder of the logic inside the completion block. This will ensure that the logic doesn’t execute until you have a value for returnAddress.

    - (void)someMethodYouCall 
    {
        NSLog(@"Begin");
        __block NSString *returnAddress = @"";
    
        [self.geoCoder reverseGeocodeLocation:self.locManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
            if(error){
                NSLog(@"%@", [error localizedDescription]);
            }
    
            CLPlacemark *placemark = [placemarks lastObject];
    
            startAddressString = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                                  placemark.subThoroughfare, placemark.thoroughfare,
                                  placemark.postalCode, placemark.locality,
                                  placemark.administrativeArea,
                                  placemark.country];
            returnAddress = startAddressString;
    
            //[self.view setUserInteractionEnabled:YES];
    
            NSLog(returnAddress);
            NSLog(@"Einde");
    
            // call a method to execute the rest of the logic 
            [self remainderOfMethodHereUsingReturnAddress:returnAddress];
        }];
    // make sure you don't perform any operations after reverseGeocodeLocation.
    // this will ensure that nothing else will be executed in this thread, and that the
    // sequence of operations now follows through the completion block.
    }
    
    - (void)remainderOfMethodHereUsingReturnAddress:(NSString*)returnAddress {
       // do things with returnAddress.
    }
    

    Or you can use NSNotificationCenter to send a notification when reverseGeocodeLocation is complete. You can subscribe to these notifications anywhere else you need it, and complete the logic from there. Replace [self remainderOfMethodHereWithReturnAddress:returnAddress]; with:

    NSDictionary *infoToBeSentInNotification = [NSDictionary dictionaryWithObject:returnAddress forKey:@"returnAddress"];
    
    [[NSNotificationCenter defaultCenter] 
        postNotificationName:@"NameOfNotificationHere" 
        object:self
        userInfo: infoToBeSentInNotification];
        }];
    

    Here’s an example of using NSNotificationCenter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.