1

I'm programming a feed reader on the iOS platform and, when parsing the json result, i create an array with objects that represent every feed. These object'll be successively push to a NSTableView or to a map (they havgeolocated information). Sometimes happen that the feed does not return the location information, but return the foursquare Id of the place, so I have to contact the foursquare server and get the information. Wath's the best way to do this? (I so want to know when all the feed in the array has retrieved their information, so I can push all on a map and in the tableview)

Thanks

Pablosproject
  • 1,374
  • 3
  • 13
  • 33

1 Answers1

1

You could create an NSOperationQueue and add the operations to fetch the information from the server, then observe the "operations" key path of the queue. When operations.count == 0, then do your push to the map and tableview.

Edit:

You aren't polling, per se - you are observing the property and receiving notification of any changes.

Add yourself as an observer of your queue's operations property.

[self.runningQueue addObserver:self forKeyPath:@"operations" options:0 context:NULL];

Then implement the following:

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
                     change:(NSDictionary *)change context:(void *)context
{
    if (object == self.runningQueue && [keyPath isEqualToString:@"operations"]) {
        if ([self.runningQueue.operations count] == 0) {
            // push to table view and map view
        }
    }
    else {
        [super observeValueForKeyPath:keyPath ofObject:object 
                           change:change context:context];
    }
}

See this thread.

Community
  • 1
  • 1
tronbabylove
  • 1,102
  • 8
  • 12