GCD

GCD: grand center dispatch is support for systems with  mutli-core processors.It's really useful when you develop a iOS application or a iOS games. I like this feature!

Ok, let me show you how to use dispatch:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

// please do something like request net server; download fiel, load big picture   

  [self doSomething];
  NSLog (@"SecondThread: %@", [NSThread currentThread]);
  dispatch_async(dispatch_get_main_queue(), ^{

      NSLog (@"MainThread: %@", [NSThread currentThread]);

      [self callbackMainThread];

      //you can refesh the UI

  });

});

Ok, that's all, isn't it so powerful? i think it is bettwer than you to use create a new NSThread, do something on the new thread , and call peferSelectorOnMainThread:

and you will find dispatch_get_main_queue() will return the mainQueue,and mostly, mainQueue is the UIKit queue.But if you need to dispatch_async to the specified queue

you can use dispatch_get_current_queue and store this queue.

enjoy it!

 

posted on 2013-03-04 23:21  CP0000  阅读(173)  评论(0)    收藏  举报

导航