-(void)doWork:(id)sender
{
NSDate *startTime=[NSDate date];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *fetchedData=[self fetchSomethingFromServer];
NSString *processedData=[self processData:fetchedData];
NSString *firstResult=[self calculateFirstResult:processedData];
NSString *secondResult=[self calculateSecondResult:processedData];
NSString *resultSummary=[NSString stringWithFormat:@"First:[%@]\nSecond:[%@]",firstResult,secondResult];
UITextView *textView=(UITextView *)[self.view viewWithTag:102];
textView.text=resultSummary;
NSDate *endTime=[NSDate date];
NSLog(@"Completed in %f Seconds",[endTime timeIntervalSinceDate:startTime]);
});
}
一直比较一知半解,没正经用过,好好看看。
2013-04-01 14:54:39.742 Rubic's Cube No StoryBoard[2891:15807] bool _WebTryThreadLock(bool), 0xa068ce0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 0x56966a9 WebThreadLock
2 0x4eaa7e -[UITextView setText:]
3 0xbb0a __37-[ForInterviewViewController doWork:]_block_invoke_0
4 0x1a3053f _dispatch_call_block_and_release
5 0x1a42014 _dispatch_client_callout
6 0x1a332e8 _dispatch_root_queue_drain
7 0x1a32fcb _dispatch_worker_thread3
8 0x9836bb24 _pthread_wqthread
9 0x9836d6fe start_wqthread