Multiple serial URL requests in Objective-C / iOS I want to check the existence of various API endpoints by doing serial URL request. If the first one fails, I want to try the second one, if the second fails I want to try the third one, etc.

Here is some code I use to do this:

self.apiEndpoint = kApiAjaxEndpoint;
[self testEndpointWithBlock:^(id response, NSError *error) {
    if (error) {
        self.apiEndpoint = kApiAjaxLegacyEndpoint;
        [self testEndpointWithBlock:^(id response, NSError *error) {
            if (error) {
                self.apiEndpoint = kApiRestEndpoint;
            }
            [self saveApiEndpoint];
        }];
    } else {
        [self saveApiEndpoint];
    }
}];


So for now I'm only testing for 2 API endpoints but the moment I add a new endpoint I would need to add another call to testEndpointWithBlock: with error handling code.

I was wondering if you can think of a more elegant way of doing this?
Create several instances of NSOperation
Set dependencies so that one runs after another.
Add to a private NSOperationQueue. 
Cancel all operations in a queue if a match is found.