16
Grand Central Dispatch ʞˈ˕˓˖˔˟ ʏ.ʠ., iOS-developer, MadAppGang

Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

  • Upload
    others

  • View
    20

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

Grand Central Dispatch . ., iOS-developer, MadAppGang

Page 2: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

iOS-

Page 3: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

GCD - API .

Page 4: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

П а ва я

Э в

П в

Page 5: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE
Page 6: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

_PRIORITY_DEFAULT, 0), ^{

[self goDoSomethingLongAndInvolved];

NSLog(@"Done doing something long and involved");

});

Page 7: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

[self goDoSomethingLongAndInvolved];

dispatch_async(dispatch_get_main_queue(), ^{

[textField setStringValue:@"Done doing something long and involved"];

});

});

Page 8: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

.

__block NSString *stringValue;

dispatch_sync(dispatch_get_main_queue(), ^{

stringValue = [[textField stringValue] copy];

});

[stringValue autorelease];

Page 9: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

dispatch_queue_t bgQueue = myQueue;

dispatch_async(dispatch_get_main_queue(), ^{

NSString *stringValue = [[[textField stringValue] copy] autorelease];

dispatch_async(bgQueue, ^{

// use stringValue in the background now

});

});

Page 10: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE
Page 11: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

И : for(id obj in array) { [self doSomethingIntensiveWith:obj]; } Па а ав ( в ащ щ а doSomethingIntensiveWith:obj): dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); for(id obj in array) { dispatch_async(queue, ^{ [self doSomethingIntensiveWith:obj]; }); }

Page 12: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

. И .

dispatch_queue_t queue =

dispatch_get_global_qeueue(DISPATCH_QUEUE_PRIORITY_DEFAUL

T, 0);

dispatch_group_t group = dispatch_group_create();

for(id obj in array) { dispatch_group_async(group, queue, ^{

[self doSomethingIntensiveWith:obj];

});

} dispatch_group_wait(group, DISPATCH_TIME_FOREVER);

dispatch_release(group);

[self doSomethingWith:array];

Page 13: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

. И .

dispatch_queue_t queue = dispatch_get_global_qeueue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_group_t group = dispatch_group_create(); for(id obj in array) { dispatch_group_async(group, queue, ^{ [self doSomethingIntensiveWith:obj]; }); } dispatch_group_notify(group, queue, ^{ [self doSomethingWith:array]; }); dispatch_release(group);

Page 14: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

. И .

С ва а в я :

dispatch_queue_t queue =

dispatch_get_global_qeueue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_apply([array count], queue, ^(size_t index){

[self doSomethingIntensiveWith:[array objectAtIndex:index]];

});

[self doSomethingWith:array];

А ва а в я :

dispatch_queue_t queue =

dispatch_get_global_qeueue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(queue, ^{

dispatch_apply([array count], queue, ^(size_t index){

[self doSomethingIntensiveWith:[array objectAtIndex:index]];

});

[self doSomethingWith:array];

});

Page 15: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

-

К

Ш

Page 16: Grand Central Dispatch - AltexSoftit-perspektiva.altexsoft.com/past-years/documents/... · ÈÓÈÇÃÚÃÊÃÇ ÃÐËÌÅÑÚÈÓÈÇß ÓËÏÈÓZ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

! ?

Д а :

[email protected]

iOS-developer, MadAppGang