我的应用程序在后台队列中处理套接字连接。在将从连接队列调用的助手类中,我必须访问核心数据来执行验证(fetch请求)。如何执行主队列中的核心数据获取并将值传递给连接队列?
守则是:
-(void)getIsFavourite {
//Execute the following codes in Main thread
id <CHFavouriteUserDao>dao =[CHServiceRepository findService:@protocol(CHFavouriteUserDao)];
//findFavouriteUserByName will execute a fetch request and return a NSManagedObject
FavouriteUser *user = [dao findFavouriteUserByName:self.uniqueIdentifier];
//Switch back to the background queue
if (user!= nil) {
[self setIsFavourite:YES];
}performSelectorOnMainThread:withObject:waitUntilDone:YES。但是它将套接字执行移至主队列并冻结应用程序。dispatch_get_main_queue(),但问题是如何访问正在运行套接字连接的后台队列(不推荐dispatch_get_current_queue)。发布于 2014-01-10 14:11:54
你试过使用NSOperationQueue吗?您可以使用
[NSOperationQueue currentQueue]和
[NSOperationQueue mainQueue]和NSOperationQueue方法-addOperations: wait :等待完成操作。
https://stackoverflow.com/questions/21045840
复制相似问题