intro to ios development
play

Intro to iOS Development Patrick Linskey @plinskey You - PowerPoint PPT Presentation

Intro to iOS Development Patrick Linskey @plinskey You Enterprise Java iOS development Me Patrick Linskey @plinskey http://versly.com Objective C Primer Object-oriented extension of C Smalltalk-like syntax Full C


  1. Intro to iOS Development Patrick Linskey @plinskey

  2. You Enterprise Java iOS development

  3. Me Patrick Linskey @plinskey http://versly.com

  4. Objective C Primer • Object-oriented extension of C • Smalltalk-like syntax • “Full” C compatibility

  5. [object message] • Messages , not methods • Braces at the beginning, which is weird. id list = [[NSArray alloc] init];

  6. Message Arguments id text = [NSString stringWithFormat:@“Hello, %@!”, @“Copenhagen”]; • Arguments are embedded in the message signature • Akin to named parameters, but order is fixed • Type overloading is unsupported

  7. Legacy C issues • Header files • Single-pass compilation • Forward-declare private messages, or careful class file definition ordering

  8. @ Directives • Objective C preprocessor directives • Strings: @“foo” • Properties: @property, @synthesize • Multi-threading: @synchronized • etc.

  9. Architecture JEE JSP JSP JSP EJB EJB EJB Entity Servlet Store Logic JAX JAX JAX Presentation Integration Business

  10. Architecture iOS Entity Widget View Store Logic Controller View EIS View Controller Model

  11. M Model V View C Controller

  12. V View Tree Root View Image View Control View Play Button Pause Button

  13. V Layout

  14. C ObjC Syntax int width = view.getWidth(); int height = view.getHeight(); view.setSize(10, 20); int width = view.width; int width = [view width]; int height = view.height; int height = [view height]; [view setWidth:10 height:20];

  15. C Listeners vs Actions button.setOnClickListener(new OnClickListener() { @Override public void onClick(Event e) { doSomething(); } }); [button addTarget:self action:@selector(doSomething) forControlEvents:TouchUpInside];

  16. C Notifications Notification Sender Observer Center

  17. C Notifications [[NotificationCenter defaultCenter] postNotificationName:PersonDidDeleteNotification object:person]; . . . [[NotificationCenter defaultCenter] addObserver:self selector:@selector(personDidDelete:) name:PersonDidDeleteNotification object:nil]; . . . - (void)personDidDelete:(Notification*)notification { Person *person = [notification object]; ... }

  18. C Delegates @protocol ListViewDelegate - (int)numberOfItemsInListView:(ListView*)list; - (ListItem*)listView:(ListView*)list itemAtIndex:(int)i; ... @optional - (void)listView:(ListView*)list didSelectItemAtIndex:(int)i; ... @end

  19. Concurrency Any sufficiently advanced bug is indistinguishable from a feature. - Bruce Brown

  20. Concurrency

  21. Concurrency JEE

  22. Concurrency iOS

  23. Concurrency iOS Data *data = ...; Data *data = ...; [self performSelectorInBackground:@selector(processData:) id result = [self processData:data]; withObject:data]; [view display:result]; [view show]; . . . - (void)processData:(Data*)data { id result = ...; [self performSelectorOnMainThread:@selector(display:) withObject:result waitUntilDone:NO]; } - (void)display:(id)result { [view display:result]; [view show]; }

  24. Concurrency iOS [self performSelector:@selector(hideControls) withObject:nil afterDelay:3.0]; [busyIndicator show]; . . . [self processData:data]; [Object cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideControls) object:nil];

  25. Concurrency iOS Controller TouchEvent Update Views Idle

  26. Concurrency iOS [busyIndicator show]; [self performSelector:@selector(processData:) withObject:data afterDelay:0.0];

  27. Concurrency iOS

  28. Concurrency iOS Queueing Model C-level API Blocks

  29. Concurrency iOS Blocks float (^myBlock) (*myFunc)(int, int) = ^(int x, int y) { = ...; return x / (float)y; }; float result = myBlock(1, 2);

  30. Concurrency iOS Blocks int y = 2; float (^myBlock)(int) = ^(int x) { return x / (float)y; }; float result = myBlock(1);

  31. Concurrency iOS Blocks (float (^)(int)) divideByY(int y) { return ^(int x) { return x / (float)y; }; } float (^divideBy2)(int) = divideByY(2); float result = divideBy2(1);

  32. Concurrency iOS Data *data = ...; id result = [self processData:data]; [view display:result]; [view show];

  33. Concurrency iOS Data *data = ...; dispatch_async(dispatch_get_global_queue(0,0), ^{ id result = [self processData:data]; dispatch_async(dispatch_get_main_queue(), ^{ [view display:result]; [view show]; }); });

  34. Concurrency iOS Cache *cache = ...; dispatch_queue_t cacheQ = dispatch_queue_create( “com.xyz.cache”, NULL); . . . Record *record = ...; dispatch_async(cacheQ, ^{ [cache addRecord:record]; }); . . . __block Record *result; dispatch_sync(cacheQ, ^{ result = [cache recordForKey:key]; });

  35. Memory • No garbage collection! • Reference counting instead • ObjC for Mac OS has GC. iOS will too (soon? http:// bit.ly/95kn6f) • Low-memory notifications

  36. Memory alloc = create 1 retain = increase reference count +1 release = decrease reference count -1 autorelease = release later -1

  37. Memory 1. [retain] what you need later 2. [release] what you alloc or retain 3. [autorelease] what you return

  38. Memory @interface Person { String *_firstName; s String *_lastName; } ... @property String *firstName; @property String *lastName; - (String *)fullName; ... @end

  39. Memory - (void)setFirstName:(String*)newFirst { [newFirst retain]; [_firstName release]; _firstName = newFirst; }

  40. Memory [person setFirstName [person getFirstName]]; - (void)setFirstName:(String*)newFirst { [_firstName release]; [newFirst retain]; _firstName = newFirst; }

  41. Memory - (String *)fullName { String *full = [[String alloc] initWithFormat: “%s %s”, _firstName, _lastName]; return [full autorelease]; }

  42. Memory - (void)dealloc { [_firstName release]; [_lastName release]; [super dealloc]; }

  43. Memory Person *person = [[Person alloc] init]; 1 person.firstName = “Patrick”; person.lastName = “Linskey”; String *fullName = [person fullName]; Log(fullName); 2 [list add:person]; [person release]; 1 . . . 0 [list remove:person];

  44. Memory [[NotificationCenter defaultCenter] addObserver:self selector:@selector(memoryWarning:) name:MemoryWarningNotification object:nil]; . . . - (void)memoryWarning:(Notification*)notification { [cache clear]; ... }

  45. Memory - (void)viewDidUnload { [view release]; view = nil; ... [super viewDidUnload]; }

  46. Testing • Xcode has not been a shining beacon in the darkness here • Ships with SenTest and OCUnit • Integration is much better than in old Xcodes (<= 3) • GHUnit* is also popular • Basically mandatory for old Xcodes * https://github.com/gabriel/gh-unit

  47. The App Store • Walled Garden • Approval latency is unpredictable • Fast-delivery-cycle teams will find this frustrating

  48. Beta Distribution • Can distribute beta builds to a limited number of iOS devices* • Consider TestFlight https://testflightapp.com/ * 100 - 500, depending on your specifics

  49. Questions? plinskey@gmail.com @plinskey Thanks!

Recommend


More recommend