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 6870873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:44:10+00:00 2026-05-27T03:44:10+00:00

would you please consider the following method: +(void)getGravatarFromEmail: (NSString *)email ofSize:(NSString *)size toImg:(UIImage *)myImg

  • 0

would you please consider the following method:

+(void)getGravatarFromEmail: (NSString *)email ofSize:(NSString *)size toImg:(UIImage *)myImg
{
    NSString *hash = [md5 getMD5Hash:email];  // external method to calculate md5 hash
    NSURL *gravatarUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://gravatar.com/avatar/%@?s=%@",hash,size]];

    ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:gravatarUrl];
    [request setCompletionBlock:^(void) {
        NSData *data = [request responseData];
        myImg = [UIImage imageWithData:data];  // ERROR HERE!!
    }];
    [request setDelegate:self];
    [request startAsynchronous];
}

This method simply makes an API call to Gravatar to retrieve an image. I would then update ‘myImg’ with the grabbed image.

However, I’m having errors trying to assign the image into ‘myImg’ as commented in the code.
The error is:

Variable not assignable (missing __block type specifier)

Any clues for me?

  • 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-05-27T03:44:11+00:00Added an answer on May 27, 2026 at 3:44 am
    +(void)getGravatarFromEmail:(NSString *)email ofSize:(NSString *)size 
               toImg:(UIImage *)myImg {
        NSString *hash = [md5 getMD5Hash:email];  // external method to calculate md5 hash
        NSURL *gravatarUrl = [NSURL URLWithString:[NSString
               stringWithFormat:@"http://gravatar.com/avatar/%@?s=%@",hash,size]];
    
        ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:gravatarUrl];
    
        __block UIImage *blockImage = myImg;
    
        [request setCompletionBlock:^(void) {
            NSData *data = [request responseData];
            blockImage = [UIImage imageWithData:data];  // ERROR HERE!!
        }];
        [request setDelegate:self];
        [request startAsynchronous];
    }
    

    I’m still a novice when it comes to blocks, but I believe the above modifications should allow your code to compile. That said, I’m not all that sure your method is using the block properly. First, the method is confusingly named (at least for most veterans). If it returns (void), and has get in the name, it seems as though you should have a pointer to a pointer to a UIImage like so:

    +(void)getGravatarFromEmail:(NSString *)email ofSize:(NSString *)size 
                   toImg:(UIImage **)myImg;
    

    I believe if you’re returning void, that’s the only way you’re going to be able to do anything with that myImg/blockImage.

    Also, this is a class method, and you’re setting the ASIHTTPRequests delegate to your class object, rather than an instance of your object?

    Anyway, on to the error you were getting:

    By default, I believe blocks have read-only access to variables. To be able to modify the myImg (or blockImage) variable from inside the block, you need to prefix the variable with the __block keyword. (That said, because of the reasons mentioned, above, I’m not all that sure what good being able to modify that variable from inside the block is).

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

Sidebar

Related Questions

Please consider the following snippet from an implementation of the Interpreter pattern: public override
please consider the following javascript code: myObject.myMethod();.replace(/\.\w+\(/g, xxx); it gives myObjectxxx); as .myMethod( is
Please consider the following: http://jsfiddle.net/CASM6/9/ I have two rows of tabs. there are two
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider the following: I am storing around 1.2 Million TIF files ranging from
please consider the following: I have a queue of objects represented as an array.
Consider the following two Java classes: a.) class Test { void foo(Object foobar) {
Please consider the following Amount value type property which is marked as a nullable
Please pardon me for a n00bish question. Please consider the following code: public class
I would like to understand the ServiceBehavior.ConcurrencyMode property. Consider the following code on service

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.