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

intro to ios development
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Intro to iOS Development

Patrick Linskey @plinskey

slide-2
SLIDE 2

You

Enterprise Java iOS development

slide-3
SLIDE 3

Me

Patrick Linskey @plinskey http://versly.com

slide-4
SLIDE 4

Objective C Primer

  • Object-oriented extension of C
  • Smalltalk-like syntax
  • “Full” C compatibility
slide-5
SLIDE 5

[object message]

  • Messages, not methods
  • Braces at the beginning, which is weird.

id list = [[NSArray alloc] init];

slide-6
SLIDE 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
slide-7
SLIDE 7

Legacy C issues

  • Header files
  • Single-pass compilation
  • Forward-declare private messages, or

careful class file definition ordering

slide-8
SLIDE 8

@ Directives

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

Architecture

JEE

JSP JSP JSP Servlet JAX JAX JAX EJB EJB EJB Logic Entity Store

Presentation Business Integration

slide-10
SLIDE 10

Architecture

iOS

Logic Entity Store EIS Widget View

Model View Controller

View Controller

slide-11
SLIDE 11

Model View Controller

M V C

slide-12
SLIDE 12

View

V

Root View Image View Control View Play Button Pause Button Tree

slide-13
SLIDE 13

V

Layout

slide-14
SLIDE 14

int height = view.height; int height = [view height]; int width = view.width; int width = [view width];

C

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

slide-15
SLIDE 15

Listeners vs Actions

C

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

slide-16
SLIDE 16

C

Notifications

Notification Center Sender Observer

slide-17
SLIDE 17

Notifications

C

[[NotificationCenter defaultCenter] postNotificationName:PersonDidDeleteNotification

  • bject:person];

. . . [[NotificationCenter defaultCenter] addObserver:self selector:@selector(personDidDelete:) name:PersonDidDeleteNotification

  • bject:nil];

. . .

  • (void)personDidDelete:(Notification*)notification {

Person *person = [notification object]; ... }

slide-18
SLIDE 18

Delegates

C

@protocol ListViewDelegate

  • (int)numberOfItemsInListView:(ListView*)list;
  • (ListItem*)listView:(ListView*)list itemAtIndex:(int)i;

... @optional

  • (void)listView:(ListView*)list didSelectItemAtIndex:(int)i;

... @end

slide-19
SLIDE 19

Concurrency

Any sufficiently advanced bug is indistinguishable from a feature.

  • Bruce Brown
slide-20
SLIDE 20

Concurrency

slide-21
SLIDE 21

Concurrency

JEE

slide-22
SLIDE 22

Concurrency

iOS

slide-23
SLIDE 23

Data *data = ...; id result = [self processData:data]; [view display:result]; [view show]; Data *data = ...; [self performSelectorInBackground:@selector(processData:) withObject:data]; . . .

Concurrency

iOS

  • (void)processData:(Data*)data {

id result = ...; [self performSelectorOnMainThread:@selector(display:) withObject:result waitUntilDone:NO]; }

  • (void)display:(id)result {

[view display:result]; [view show]; }

slide-24
SLIDE 24

[self performSelector:@selector(hideControls) withObject:nil afterDelay:3.0]; . . .

[busyIndicator show]; [self processData:data];

Concurrency

iOS

[Object cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideControls)

  • bject:nil];
slide-25
SLIDE 25

Concurrency

iOS

TouchEvent Controller Update Views Idle

slide-26
SLIDE 26

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

Concurrency

iOS

slide-27
SLIDE 27

Concurrency

iOS

slide-28
SLIDE 28

Concurrency

iOS

Queueing Model C-level API Blocks

slide-29
SLIDE 29

(^myBlock) (*myFunc)(int, int)

Concurrency

iOS

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

slide-30
SLIDE 30

(^myBlock)(int)

Concurrency

iOS

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

slide-31
SLIDE 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);

slide-32
SLIDE 32

Concurrency

iOS

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

slide-33
SLIDE 33

iOS

Concurrency

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

slide-34
SLIDE 34

iOS

Concurrency

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]; });

slide-35
SLIDE 35
  • No garbage collection!
  • Reference counting instead
  • ObjC for Mac OS has GC.

iOS will too (soon? http:// bit.ly/95kn6f)

  • Low-memory notifications

Memory

slide-36
SLIDE 36

Memory

alloc = create retain = increase reference count release = decrease reference count autorelease = release later

1 +1

  • 1
  • 1
slide-37
SLIDE 37

Memory

  • 1. [retain] what you need later
  • 2. [release] what you alloc or retain
  • 3. [autorelease] what you return
slide-38
SLIDE 38

s

@interface Person { String *_firstName; String *_lastName; } ... @property String *firstName; @property String *lastName;

  • (String *)fullName;

... @end

Memory

slide-39
SLIDE 39
  • (void)setFirstName:(String*)newFirst {

}

Memory

[newFirst retain]; [_firstName release]; _firstName = newFirst;

slide-40
SLIDE 40
  • (void)setFirstName:(String*)newFirst {

}

Memory

[newFirst retain]; [_firstName release]; _firstName = newFirst; [person setFirstName [person getFirstName]];

slide-41
SLIDE 41

Memory

  • (String *)fullName {

String *full = [[String alloc] initWithFormat: “%s %s”, _firstName, _lastName]; return [full autorelease]; }

slide-42
SLIDE 42

Memory

  • (void)dealloc {

[_firstName release]; [_lastName release]; [super dealloc]; }

slide-43
SLIDE 43

Memory

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

1 2 1

slide-44
SLIDE 44

Memory

[[NotificationCenter defaultCenter] addObserver:self selector:@selector(memoryWarning:) name:MemoryWarningNotification

  • bject:nil];

. . .

  • (void)memoryWarning:(Notification*)notification {

[cache clear]; ... }

slide-45
SLIDE 45

Memory

  • (void)viewDidUnload {

[view release]; view = nil; ... [super viewDidUnload]; }

slide-46
SLIDE 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

slide-47
SLIDE 47

The App Store

  • Walled Garden
  • Approval latency is unpredictable
  • Fast-delivery-cycle teams will find this

frustrating

slide-48
SLIDE 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

slide-49
SLIDE 49

Questions?

plinskey@gmail.com @plinskey Thanks!