NSURLConnection中的保证令

时间:2012-02-15 21:41:22

标签: objective-c ios

让我先从一些代码开始。加载应用程序时,会调用以下内容:

//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)];

到目前为止,这段代码除了一件事外效果很好 - 我的回答是乱序的。这是可以预料的,因为程序列表比排序顺序大得多。基本上,需要发生的是我需要保证我有程序列表和排序顺序才能执行任何类型的排序算法。

不通过执行同步请求来锁定程序,在执行排序算法之前,保证我有两个方法的最佳方法是什么?当然,我可以设置BOOL标志,但我需要不断检查以确定何时收到它们。