Tuesday, 22 October 2013

GCD & Blocks

Grand Central Dispatch
• Perform complex actions in response to user input while remaining responsive.

Threading Basics
• Process can contain multiple threads, while all run concurrently.

mutex: mutual exclusion, or a lock, which ensuring that particular chunk of code can't be run by multiple threads at once.

thread-safe: Foundation framework (containing basic classes approprite for all sofrts of Obj-C programming, such as NSString, NSArray and so on) is generally considered to be thread-safe.

not thread-safe: UIKit framework (containing the classes specific to building GUI such as UIApplication, UIView and all it subclasses and so on).

main thread UIKit objects should be executed from the sam thread.

Queue: queue that 's quaranteed to always do its workd on the main thread.

Also known as closure or lambdas in other languagess. Much like a method or function, a block can take one or more parameters and specify a return value. To declare a block variable, you use the caret (^) symbol along with some additional parenthesized bits to declare parameters and return types.''

`void (^loggerBlock)(void)`

`loggerBlock = ^{ NSLog(@"Hi"); };


GCD + Blocks

   dispatch_queue_t main_queue = dispatch_get_main_queue();
    dispatch_async(main_queue, ^{

    [self createPieces];

    dispatch_async(main_queue, ^{

        [self addAnothePieceToView];


No comments:

Post a Comment

iPhone XS, XS Plus & XR Price in Malaysia

Early today I got information that the latest Apple smartphone will be released in Malaysia soon. People can pre-order the phone throught ...