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

  • SEARCH
  • Home
  • 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 9228399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:18:53+00:00 2026-06-18T05:18:53+00:00

all. I have a method: -(void)connectToServer:(NSError**)error{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //bla bla bla code; *error=[NSError

  • 0

all.
I have a method:

-(void)connectToServer:(NSError**)error{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         //bla bla bla code;
         *error=[NSError bla bla bla];
    }
}

But after that error variable no modificated. Its no block variable. How can i modify this method for mark (NSError**)error as __block variable. If __block varibale used only for local variables?

Now i solve the problem with organization local variable with __block attribute:

-(void)connectToServer:(NSError**)error{
    __block NSError *localError=*error;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         //bla bla bla code;
         localError=[NSError bla bla bla];
    }
    *error=localError;
}

But this solution not like my, because i need redeclare __block NSError *localError=*error;

  • 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-18T05:18:54+00:00Added an answer on June 18, 2026 at 5:18 am

    Mu.

    What you’re doing doesn’t make much sense. The connectToServer: method is quite likely going to return before that block sets the error variable, which means the caller isn’t going to have a valid object to look at.

    You need to have the block call another method to handle any errors that result, or run the block synchronously so that connectToServer: doesn’t return before the block has finished.

    Also, in the second case you should be following Cocoa convention for error handling and indicating that an error occurred via the direct return of the method.

    This should be rewritten as either:

    - (void)connectToServer
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //bla bla bla code including error generation
            dispatch_sync(/* Get appropriate queue; probably main */, ^{
                // Handle error somehow
            });
        });
    }
    

    Or:

    - (BOOL)connectToServer: (NSError **)e
    {
        __block BOOL success = NO;
        // Note: dispatch_sync()
        dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //bla bla bla code;
            success = /* Get success value */;
            *e = /* Get error */;
        });
        return success;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method: - (void)myMethod:(NSError *)error { [[self.data allKeys] enumerateUsingBlock:^(id obj, NSUInteger idx,
I have this method which will remove all rows from a table but I
I have a method that I'm using to output all the class names in
I have a method connection(int n) which gives me all the cells number that
All, I have a method that is currently used to invoke DLLs of return
All, I have a method that returns a List. This method is used to
All, I have a method that takes a date (YYYY-MM-DD H:M:S) from the database
When you set caret on member/method in code you have all its occurrences highlighted,
If we have a method: public void doSomething(){ synchronized(this){ //some code processing here }
I have a method void DoWork(object input) that takes roughly 5 seconds to complete.

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.