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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:51:38+00:00 2026-05-31T18:51:38+00:00

Hey im having this code so far – (id)initWithDictionary:(NSDictionary *)aDictionary { self = [super

  • 0

Hey im having this code so far


- (id)initWithDictionary:(NSDictionary *)aDictionary {
    self = [super init];
    if (!self) {
        return nil;
    }

    _userAvatar = [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
    _userId = [aDictionary objectForKey:@"user_id"];
    _username = [aDictionary objectForKey:@"username"];
    _userEmail = [aDictionary objectForKey:@"user_email"];
    return self;
}


- (UIImage *)getUserAvatar:(NSString *)avatarPath {

    __block UIImage *avatarImage = [[UIImage alloc]init];
    if ([avatarPath length] != 0) {
        [[AFFnBAPIClient sharedClient] setDefaultHeader:@"Accept" value:@"image/png"];
        [[AFFnBAPIClient sharedClient] getPath:FNB_DOWNLOAD_PATH parameters:[NSDictionary dictionaryWithObject:avatarPath forKey:@"avatar"] success:^(AFHTTPRequestOperation *operation, id image) {
            avatarImage = image;
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error");
        }];
    } else {
        UIImage *placeholderImage = [UIImage imageNamed:@"placeholder.png"];
        avatarImage = placeholderImage;
    }
    return avatarImage;
}

my problem is return self is called before the async request is finished, how do i return self with the request finished without a synchronous request?

  • 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-31T18:51:39+00:00Added an answer on May 31, 2026 at 6:51 pm

    do it like this:

    - (id)initWithDictionary:(NSDictionary *)aDictionary {
        self = [super init];
        if (self) {
    
            // for starters, it's a placeholder
            self.userAvatar = [UIImage imageNamed:@"placeholder.png"];
    
            // now go get the avatar, fill it in whenever the get finishes.
            // notice there's no return value.
            [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
    
            // make sure these are retained (or strong in ARC) properties.
            // your code looked like it was releasing these
            self.userId = [aDictionary objectForKey:@"user_id"];
            self.username = [aDictionary objectForKey:@"username"];
            self.userEmail = [aDictionary objectForKey:@"user_email"];
        }
        return self;
    }
    
    // see - no return value.  it's asynch
    - (void)getUserAvatar:(NSString *)avatarPath {
    
        // don't need a __block var here
        if ([avatarPath length] != 0) {
            [[AFFnBAPIClient sharedClient] setDefaultHeader:@"Accept" value:@"image/png"];
            [[AFFnBAPIClient sharedClient] getPath:FNB_DOWNLOAD_PATH parameters:[NSDictionary dictionaryWithObject:avatarPath forKey:@"avatar"] success:^(AFHTTPRequestOperation *operation, id image) {
    
                // self got a retain+1 while this was running.
                self.userAvatar = image;
    
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"Error");
            }];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey SO Guru's im having one heck of a job with this code public
Hey everyone i am trying to write this code and I am having problems
Hey, I'm having some trouble with this code for retrieving Google Analytic data. if($_GET['month']
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
Hey, well I'm having a problem and this weird symbol is showing up â€
Hey all, I'm having a difficult time wording this properly which is why im
hey there, Im having problems displaying my results in this program but the program
Hey guys I am having a lot of trouble trying to understand this and
Hey I'm having trouble getting my code to compare the integers of a given
Hey guys I'm trying to work my way through this but am having an

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.