Palestra sobre Mídias Sociais - Techitup Marketing Digital - Larissa Bernardes
Palestra sobre Grand Central Dispatch no [self sp]
-
Upload
diego-chohfi -
Category
Documents
-
view
218 -
download
0
Transcript of Palestra sobre Grand Central Dispatch no [self sp]
![Page 1: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/1.jpg)
Diego Chohfi - @dchohfi
Diego Chohfi Turini
[self SP];
Paralelismo transparenteGCD(Grande Central Dispatcher)
Monday, March 19, 12
![Page 2: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/2.jpg)
Diego Chohfi - @dchohfi
“Quando precisamos de paralelismo temos n problemas, e quando usamos temos n^2 problemas”- @qmx
Monday, March 19, 12
![Page 3: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/3.jpg)
Diego Chohfi - @dchohfi
^Primeiro:Blocos
Monday, March 19, 12
![Page 4: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/4.jpg)
Diego Chohfi - @dchohfi
int (^bloco)(int) = ^(int numero){ return numero *10;};
retorno
variável
paramêtro
broco
nome param
corpo do broco
Véi, na boa.. bloco?
Monday, March 19, 12
![Page 5: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/5.jpg)
Diego Chohfi - @dchohfi
Bloco = tipo
typedef double(^Dividir)(double, double);
@property (copy) Dividir dividir;
dividir = ^( double dividendo, double divisor){return dividendo / divisor;
}; NSLog(@"%f.0", self.dividir(10,2));
Monday, March 19, 12
![Page 6: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/6.jpg)
Diego Chohfi - @dchohfi
int variavelExterna = 10; void (^block)(int) = ^(int mother){ NSLog(@"OF JOBS %i, guardei escopo!", modern * variavelExterna); }; block(10);
NSArray *OMG = [[NSArray alloc] initWithObjects:@"MOTHER", @"OF", @"JOBS", nil];
[OMG enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(obj); }];
TWTweetComposeViewController *tweet = [[TWTweetComposeViewController alloc] init]; [tweet setCompletionHandler:^(TWTweetComposeViewControllerResult result){ if(result == TWTweetComposeViewControllerResultDone){ NSLog(@"AI QUE LOUCURA, TWEETEI"); } }];
Monday, March 19, 12
![Page 7: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/7.jpg)
Diego Chohfi - @dchohfi
GCD, it’s all about queueing(based on kqueue)
Monday, March 19, 12
![Page 8: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/8.jpg)
Diego Chohfi - @dchohfi
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{ NSLog(@"Calculando o tamanho do universo, no iPhone 3");});
#define! DISPATCH_QUEUE_PRIORITY_HIGH ! 2#define! DISPATCH_QUEUE_PRIORITY_DEFAULT 0#define! DISPATCH_QUEUE_PRIORITY_LOW ! (-2)#define! DISPATCH_QUEUE_PRIORITY_BACKGROUND! INT16_MIN
Monday, March 19, 12
![Page 9: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/9.jpg)
Diego Chohfi - @dchohfi
Criando queue’s
dispatch_queue_t minhaQueue = dispatch_queue_create("br.com.caelum", NULL); dispatch_async(minhaQueue, ^{ });
Monday, March 19, 12
![Page 10: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/10.jpg)
Diego Chohfi - @dchohfi
dispatch_async(queue, ^{ [NSThread sleepForTimeInterval:2];
asyncLabel.text = @"UNIVERSO CALCULADO";});
syncLabel.text = @"Calculando o universo";
Alterando views, cuidado!
dispatch_async(queue, ^{[NSThread sleepForTimeInterval:2];dispatch_async(dispatch_get_main_queue(), ^{
asynchLabel.text = @"UNIVERSO CALCULADO";});
}); syncLabel.text = @"Calculando o universo";
Monday, March 19, 12
![Page 11: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/11.jpg)
Diego Chohfi - @dchohfi
Criando Grupos
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group,queue,^{ [NSThread sleepForTimeInterval:1];
NSLog(@"Calculando o tamanho do sol");});
dispatch_group_async(group,queue,^{NSLog(@"Esperando a mulher fazer compras");
});
dispatch_group_notify(group,queue,^{NSLog(@"Será executado após os dois blocos");
});
Monday, March 19, 12
![Page 12: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/12.jpg)
Diego Chohfi - @dchohfi
dispatch_async(queue,^{[NSThread sleepForTimeInterval:1];for (int i=0; i<10; i++) {
valorMagico++;}
});
Valores fora do escopo
__blockint valorMagico = 0;
Monday, March 19, 12
![Page 13: Palestra sobre Grand Central Dispatch no [self sp]](https://reader031.fdocuments.in/reader031/viewer/2022020115/5555be8bd8b42afe5d8b51a2/html5/thumbnails/13.jpg)
Diego Chohfi - @dchohfi
dispatch_queue_t queue = dispatch_get_global_queue(0, 0); dispatch_apply(10, queue, ^(size_t i){
NSLog(@"Numero: %zu", i);//não garante ordem});
Batch queueing
Monday, March 19, 12