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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:13:14+00:00 2026-06-13T08:13:14+00:00

Im trying to understand some code I found on the internet. Im trying to

  • 0

Im trying to understand some code I found on the internet. Im trying to tweak it so I can use it in my own program. In my program Ive made this a instance method of a singleton. I understand most of what this is doing but dont get the “block” part. What is the block for? and in my implementation, what should I pass as the parameter in place of NSSet Photos. I dont understand this since, Im actually hoping to “get” photos from the server for that location. So what am I sending ?

 + (void)photosNearLocation:(CLLocation *)location
                 block:(void (^)(NSSet *photos, NSError *error))block
 {
    NSLog(@"photosNearLocation - Photo.m");
    NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
    [mutableParameters setObject:[NSNumber 
    numberWithDouble:location.coordinate.latitude] forKey:@"lat"];
    [mutableParameters setObject:[NSNumber 
    numberWithDouble:location.coordinate.longitude] forKey:@"lng"];

    [[GeoPhotoAPIClient sharedClient] getPath:@"/photos"
                               parameters:mutableParameters
                                  success:^(AFHTTPRequestOperation *operation, id JSON)
    {
      NSMutableSet *mutablePhotos = [NSMutableSet set];
      NSLog(@" Json value received is : %@ ",[JSON description]);
      for (NSDictionary *attributes in [JSON valueForKeyPath:@"photos"])
      {
        Photo *photo = [[Photo alloc]
                        initWithAttributes:attributes];
        [mutablePhotos addObject:photo];
      }

      if (block) {
        block([NSSet setWithSet:mutablePhotos], nil);
       }
     }failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
       if (block)
      {
        block(nil, error);
        NSLog(@"Error in Photo.m line 145 %@ ", [error description]);
       }
      }];
      }
  • 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-13T08:13:15+00:00Added an answer on June 13, 2026 at 8:13 am

    No need to pass anything for the photo set. It’s a parameter to the block. The caller’s job is to pass a block that will be invoked when the method finishes some asynchronous work. So you’d call it like this:

    // let's setup something in the caller's context to display the result
    // and to demonstrate how the block is a closure - it remembers the variables
    // in it's scope, even after the calling function is popped from the stack.
    
    UIImageView *myImageView = /* an image view in the current calling context */;
    
    [mySingleton photosNearLocation:^(NSSet *photos, NSError *error) {
        // the photo's near location will complete some time later
        // it will cause this block to get invoked, presumably passing
        // a set of photos, or nil and an error
        // the great thing about the block is that it can refer to the caller context
        // as follows....
    
        if (photos && [photos count]) {
            myImageView.image = [photos anyObject];   // yay.  it worked
        } else {
            NSLog(@"there was an error: %@", error);
        }
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am now trying to understand some code and I have found a pattern,
I'm trying to understand some code I found the open source oauth-php library. The
I'm trying to understand a piece of code I should manage. I found some
I've in inherited some code that I'm trying to understand and any searching I
I am trying to understand the Javascript event handling. I like some code to
i have some code that i am trying to recompile and understand, but i
I have some legacy C++ code that I am trying to understand a bit
I am trying to fully understand the process pro writing code in some language
I’m trying to understand code from http://www.yesodweb.com/book/conduits . After some fixes (like replacing Resource
This might be difficult to answer. I am trying to understand some codebase and

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.