Let me start off with some code. When the application loads, it calls the following:
//Creates custom URL for request, loads the request, and upon completion (as per the delegate response, it runs the selector)
//List of programs
URLCreator * getListURL = [[URLCreator alloc] initStandard:@"getList"];
WebManager *getListWM = [[WebManager alloc]init];
[getListWM load:[getListURL finalURL] withSelector:@selector(createProgramList)];
//Sorting order for program list
URLCreator * getSortURL = [[URLCreator alloc] initStandard:@"getSort"];
WebManager *getSortWM = [[WebManager alloc]init];
[getSortWM load:[getSortURL finalURL] withSelector:@selector(sortThroughPrograms)];
This code so far works well except for one thing – my responses come out of order. This is to be expected because the list of programs is much larger than the sorting order. Basically, what needs to happen is I need to guarantee I have the list of programs AND the sorting order before I can perform any type of sorting algorithm.
Without locking up the program by doing a synchronous request, what is the best way to guarantee that I have BOTH before performing the sorting algorithm? Sure, I can set BOOL flags, but I would need to constantly check to see when both have been received.
You could use NSOperationQueue for this.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html