This document discusses how to use threads and concurrency in iOS development to take advantage of multi-core processors. It notes that as processors have increased cores, iOS devices now have dual-core or quad-core CPUs. The document recommends using threads and concurrency through Grand Central Dispatch or operation queues to perform tasks in parallel without freezing the user interface. It provides examples of animations, network requests, and long-running tasks that can benefit from threads. It also warns that some UI-related tasks must remain on the main thread.
1 of 17
Download to read offline
More Related Content
2013-05-15 threads. why and how
1. Why we should use thread and how to do it
with no additional efforts.
2. ? Dominik Haska ¨C Research Software
Developer in Jeppesen a Boeing Company
? 9 years of professional programming
including 1 year in IOS
3. ? Why
? Moore law and physics limitations
? How
? how to use the potentially power of multicore
devices easily and properly
7. ? iPhone 1 ¨C 1 CPU 412 MHz
? iPhone 5 ¨C 2 CPU 1300 MHz
? iPad 1 ¨C 1 CPU 1000 MHz
? iPad 4 (retina) ¨C 2 CPU 1400 MHz
8. ? all animations:
? GPU is a massive multiprocessor unit
? Just use the animation block
[UIView animateWithDuration:1.0 animations:^{
firstView.alpha = 0.0;
secondView.alpha = 1.0;
}];
9. [UIView beginAnimations:@"ToggleViews" context:nil];
[UIView setAnimationDuration:1.0];
// Make the animatable changes.
firstView.alpha = 0.0;
secondView.alpha = 1.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];
13. ? Some code have to be executed in main
thread
? [NSString sizeWithFont] ¨C sometimes ¨C once
per 1-2 day crashes app
? [[UIView alloc] init]
? [view addSubview¡]
? Solution
? Delegate and perform on main thread
performSelectorOnMainThread:@selector(
? Use NSAttributedString to work with UIKit Additions
? Always check when app crashes in which thread are
you
15. ? Long time for response
? Multiple resources needed in parraler
(webbrowsers)
? Ready to use in ios:
? [SSLConnection
sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse*
response, NSData* data, NSError*
error){ ¡ }
16. ? You have multicore devices ¨C use this
? Look for simplest solution ¨C use library as
much as possible
? Focus on user interaction ¨C do not freeze your
apps
? Be carefull with debugging ¨C single thread
app is much more testable ¨C much much
more
? I work for jeppesen boeing company ¨C if i
show you sample code I have to kill you ;) ¨C
but next time I try to be better
17. ? developer.apple.com
? http://www.gotw.ca/publications/concurrenc
y-ddj.htm - the free lunch is over
? http://www.robotswillstealyourjob.com/ -
robots are stealing your job ¨C and engineers
help them to
? http://www.extremetech.com/computing/11
6561-the-death-of-cpu-scaling-from-one-
core-to-many-and-why-were-still-stuck/2