Slide 1

Slide 1 text

Developing for iOS - When to do what and how @martincronje [email protected]

Slide 2

Slide 2 text

agenda

Slide 3

Slide 3 text

the market

Slide 4

Slide 4 text

7 billion mobile phones

Slide 5

Slide 5 text

1,5 billion smartphones

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

why iOS?

Slide 8

Slide 8 text

Android won, right?

Slide 9

Slide 9 text

Android has 75% market share

Slide 10

Slide 10 text

Platform Mobile OS 2013[a] Mobile OS 2017[a] App downloads 2013[b] Web usage 2013[c] 3.9% 10.2% 3.7% 1.5% 16.9% 17.9% 47.8% 54.91% 75.3% 68.3% 48.6% 25.7% 3.9% 3.6% - 17,89% Target platform (Global market share)? a) IDC Worldwide Mobile Phone Tracker, June 6, 2012 b) XYO Global App Download Reports 1.0 c) NetMarketShare Mobile Operating System Aug 2013 …

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

native vs. hybrid vs. web

Slide 15

Slide 15 text

When you want the worst of both... Hybrid:

Slide 16

Slide 16 text

!= != Hybrid…

Slide 17

Slide 17 text

“The biggest mistake we’ve made as a company is betting on HTML5 over native.” Mark Zuckerberg

Slide 18

Slide 18 text

When you want to extend your phone... Native:

Slide 19

Slide 19 text

When you want cost-effective... Web:

Slide 20

Slide 20 text

Approach characteristics User Experience Device Access Works offline Cost of ownership Reach Native Highest Yes Yes Highest Specific Cross Platform High Yes * Yes * High ** Common * Hybrid Low Yes * Partially * Medium ** Common * Web (Rich) Low Limited No Low 30% Web (Light) Lowest None No Lowest 80% * Depends on framework and approach chosen. ** Depending on support offered by relevant platform

Slide 21

Slide 21 text

becoming an iOS developer

Slide 22

Slide 22 text

Developing Apps for iPhone and iPad (Winter 2013)

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

my setup

Slide 26

Slide 26 text

My setup MacBook Pro 15” (Retina Display, 8GB RAM, i7, SSD) OSX Mountain Lion 10.8.4 Windows 8 Xcode / AppCode Xamarin Studio Visual Studio 2012 Xamarin Studio VMWare Fusion

Slide 27

Slide 27 text

My software on OSX IDE Xcode, AppCode and Xamarin Studio Editors vi and Sublime Shell iTerm, zsh and oh-my-zsh Misc Homebrew, Alfred, AirMail, Fanstical and 1Password

Slide 28

Slide 28 text

Objective-C

Slide 29

Slide 29 text

Classes

Slide 30

Slide 30 text

Methods [myObject insertObject:objectToInsert atIndex:0];!

Slide 31

Slide 31 text

-(id)doYouKnowTheMuffinMan:(TheMuffinMan *)theMuffinMan;!

Slide 32

Slide 32 text

Blocks int result = myBlock(4); // result is 28!

Slide 33

Slide 33 text

Literals NSNumber *number;! ! number = [NSNumber numberWithChar:'X'];! number = [NSNumber numberWithInt:12345];! number = [NSNumber numberWithUnsignedLong:12345ul];! number = [NSNumber numberWithLongLong:12345ll];! number = [NSNumber numberWithFloat:123.45f];! number = [NSNumber numberWithDouble:123.45];! number = [NSNumber numberWithBool:YES];! number = @'X’;! number = @12345;! number = @12345ul;! number = @12345ll;! number = @123.45f;! number = @123.45;! number = @YES;!

Slide 34

Slide 34 text

Literals dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3]! forKeys:@[k1, k2, k3]];! ! dict = @{ k1 : o1, k2 : o2, k3 : o3 };! ! ! ! ! array = [NSArray arrayWithObjects:a, b, c, nil];! ! array = @[ a, b, c ];! !

Slide 35

Slide 35 text

Automatic Reference Counting (ARC)

Slide 36

Slide 36 text

ObjectiveC is a wild horse

Slide 37

Slide 37 text

Cocoa

Slide 38

Slide 38 text

MVC

Slide 39

Slide 39 text

Notification centre

Slide 40

Slide 40 text

Key-value observing

Slide 41

Slide 41 text

Animated - (void)reset:(BOOL)animated {! if(animated) {! [UIView animateWithDuration:0.3f! delay:0.0f! options:(UIViewAnimationOptionCurveEaseIn)! animations:! ^{! self.front.alpha = 1.0;! self.front.frame = CGRectMake(0, 0, width, height);! } completion:nil];! } else {! self.front.alpha = 1.0;! }! }!

Slide 42

Slide 42 text

Tips

Slide 43

Slide 43 text

Asynchronous Processing [NROperationQueue runInBackground:^() {! // Some long-running operation! [NROperationQueue runOnMain:^() { ! // Update the UI ! }];! }];! ! ! ! @implementation NROperationQueue! + (void)runOnMain:(void (^)(void))block {! [[NSOperationQueue mainQueue] addOperationWithBlock:block];! }! + (NSOperationQueue *)backgroundQueue {! return [self instance].backgroundQueue; // NSOperationQueue ! }! @end!

Slide 44

Slide 44 text

Factory Methods #import "ECMIncident.h"! #import "NSDictionary+Conversions.h"! ! @implementation ECMIncident! ! - (id)initFromJSON:(NSDictionary *)jsonObject {! if(self = [super init]) {! self.activity = [jsonObject stringForKey:@"activity"];! self.age = [jsonObject numberForKey:@"age"];! }! return self;! }! ! + (ECMIncident *)incidentFromJSON:(NSDictionary *)dictionary {! return [[ECMIncident alloc] initFromJSON: dictionary];! }! ! @end!

Slide 45

Slide 45 text

Test-driven development -  (void)testShouldParseJsonIntoModel {! NSData *content = [self loadFile:@"incident.simple"];! ! NSError *error = nil;! NSDictionary *jsonObject = [NSJSONSerialization ! JSONObjectWithData : content! options : nil ! error : &error];! ! ECMIncident *incident = [ECMIncident incidentFromJSON: jsonObject];! ! STAssertNotNil(incident, @"Expected populated object");! STAssertTrue([incident.summary isEqualToString:@"Foo Bar"]);! }!

Slide 46

Slide 46 text

Some other tips •  Information hiding •  Singletons and dependency injection

Slide 47

Slide 47 text

Frameworks

Slide 48

Slide 48 text

Cocoapods $ gem install cocoapods! $ cat Podfile! platform :ios, :deployment_target => '6.0'! pod 'AFNetworking'! pod 'Objection'! pod 'Facebook-iOS-SDK'! pod 'OCHamcrest'! ! $ pod setup!

Slide 49

Slide 49 text

Frank Feature: General (Main)! Scenario: My details! ! Given I logged in with "my-user-1" ! And I wait for "Logging in…" to go away! When I touch the "My Details" table cell! Then I wait to see a navigation bar titled "My Details"! And I should see a table containing the following:! | Column 1 |! | Username | ! | Email |! | First Name |! ...! When I type "Martin" into the Username text field! And I ...!

Slide 50

Slide 50 text

Frank Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_mark|! quote = get_selector_quote(expected_mark)! message = "waited to see a navigation bar titled #{quote}#{expected_mark}#{quote}"! wait_until( :timeout => 30, :message => message) {! element_exists( "navigationItemView marked:#{quote}#{expected_mark}#{quote}" )! }! end! ! When /^I touch the "([^\"]*)" table cell$/ do |name|! touch("tableView view marked:'#{name}'")! end! ! When /^I type "([^"]*)" into the ([^"]*) text field$/ do |value, field|! selector = "label marked:'#{field}' parent tableViewCell textField"! text_fields_modified = frankly_map(selector, "setText:", value )! raise "could not find text fields to update" if text_fields_modified.empty?! end!

Slide 51

Slide 51 text

Frank Then /^I should see a table containing the following:$/ do |table|! ! table.rows.each do |row|! selector = String.new! ! row.each do |cell|! if selector.empty?! selector = "tableView view marked:'#{cell}'"! else! selector << " parent tableViewCell view marked:'#{cell}'"! end! end! check_element_exists( selector )! end! end!

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

mono vs objective-c

Slide 54

Slide 54 text

Development platform Platform IDE SDK Language OS Visual Studio Windows Phone C#, etc. Windows Xcode Cocoa Touch Objective-C OSX Eclipse Android Java All

Slide 55

Slide 55 text

Development platform Platform IDE SDK Language OS Visual Studio Windows Phone C#, etc. Windows Visual Studio Xamarin Studio Cocoa Touch C# (Compiled to ObjC) Windows* / OSX Visual Studio Xamarin Studio Android C# Windows / OSX * OSX build server required

Slide 56

Slide 56 text

Sharing Code Application Layer User Interface Android SDK Android SDK Cocoa Touch Cocoa Touch Win Phone SDK Win Phone SDK Shared - Model - Data Access - Business Logic - Service Access

Slide 57

Slide 57 text

Android SDK Cocoa Touch Win Phone SDK Xamarin.Mobile App Layer Sharing Code UI Android SDK Cocoa Touch Win Phone SDK Shared Business Logic Adapter pattern View Controller