Transcript
Page 1: iOS for Android Developers (with Swift)

iOS for Android Developers

with Swift

David Truxall, Ph.D.

http://bit.ly/androidToIos

Page 2: iOS for Android Developers (with Swift)

About Me@davetrux

blog.davidtruxall.com

Page 3: iOS for Android Developers (with Swift)

You

● Know Java● Know Android● Don’t know Swift● Don’t know iOS● Need a Mac

Page 4: iOS for Android Developers (with Swift)

Goal

Learn basic iOS concepts for someone

familiar with Android

(using Swift)

Page 5: iOS for Android Developers (with Swift)

Why?● Do I hate Android now?

● Neither platform is “the winner”

● Clients want both platforms

● You can make more money

● Swift is the new hotness in mobile

● Objective-C

Page 6: iOS for Android Developers (with Swift)

Agenda

1. Brief language intro

2. Project/Tool Structure

3. App Architecture

4. Coding Demo

Page 7: iOS for Android Developers (with Swift)

Swift

● Object-oriented AND Functional

● C family

● Cleaner, simpler, safer than Objective-C

● Modern features

Page 8: iOS for Android Developers (with Swift)

Compare- (NSString*) concatenateString:(NSString*)stringA withString:(NSString*)stringB

{

NSString *finalString = [NSString stringWithFormat:@"%@%@", stringA, stringB];

return finalString;

}

func concatenateString(stringA: String, stringB: String) ->String {

let result = stringA + stringB

return result

}

Page 9: iOS for Android Developers (with Swift)

Swift Features

● Closures

● Tuples and multiple return values

● Generics

● Structs that support methods

● Functional programming patterns

Page 10: iOS for Android Developers (with Swift)

Java/Android Swift/iOS

import com.package.name; import frameworkname

int counter; var counter :Int

static final int LEVELS = 8; let levels = 8

private private

public public

- internal (*)

protected -

Language

Page 11: iOS for Android Developers (with Swift)

Java/Android Swift/iOS

class Foo extends Bar {} class Foo : Bar

interface Baz{} protocol Baz

class Foo implements Baz{} class Bar : Baz {}

Foo(); init()

void doWork(String arg){} func doWork(arg: String) -> Void

Foo item = new Foo(); var item : Foo = Foo()

item.doWork(arg); item.doWork(arg)

Objects

Page 12: iOS for Android Developers (with Swift)

Optionals

? - Has a value or no value at all (nil)

! - Implicitly Unwrapped Optional

Page 13: iOS for Android Developers (with Swift)

Swift OOclass VideoMode {

var resolution : Resolution = Resolution()

var interlaced = false

let frameRate = 60.0

var name: String?

func setUpMode(modeName: String) -> Void {<do stuff>}

}

Page 14: iOS for Android Developers (with Swift)

Swift Functionalfunc addTwoInts(a: Int, b: Int) -> Int {

return a + b

}

var addFunction: (Int, Int) -> Int = addTwoInts

func printMath(mathFunction: (Int, Int) -> Int, a: Int, b: Int) {

println("Result: \(mathFunction(a, b))")

}

printMath(addTwoInts, 3, 5)

Page 15: iOS for Android Developers (with Swift)

Xcode

● Free

● It’s an IDE

● Click not double-click

● Virtual file organization

Page 16: iOS for Android Developers (with Swift)

Demo

Page 17: iOS for Android Developers (with Swift)

Application Architecture

Model - View - Controller

UI Organization and Plumbing

Page 18: iOS for Android Developers (with Swift)

Model - View -Controller

Controller

ModelView

Update

User Action

Update

Notify

Page 19: iOS for Android Developers (with Swift)

Android != Model-View-Controller

Activity

ProviderLayout

Update

Notify

Page 20: iOS for Android Developers (with Swift)

iOS Model - View -Controller

ViewController

Custom ClassesUIView

Update via IBOutlet

Respond to IBAction

Update

Notify

Page 21: iOS for Android Developers (with Swift)

UI Organization

Android iOS

Layout XML XIB (NIB)

- Storyboard

- IBOutlet

- IBAction

Intent ~ Segue

Page 22: iOS for Android Developers (with Swift)

Lifecycle EventsAndroid iOS

onCreate (onCreateView) viewDidLoad

onStart viewWillAppear

onResume viewDidAppear

onPause viewWillDisappear

onStop viewDidDisappear

Page 23: iOS for Android Developers (with Swift)

UI ElementsAndroid iOS

TextView UILabel

EditText (single line) UITextField

EditText (multi-line) UITextView

Button UIButton

RadioGroup SegmentedControl

CheckBox, ToggleButton UISwitch

Page 24: iOS for Android Developers (with Swift)

Delegation

● Class has a property that is a protocol

● Second class implements the protocol

● Second class assigned to the variable in

the first class

Page 25: iOS for Android Developers (with Swift)

Converting an App

Page 26: iOS for Android Developers (with Swift)

Yet Another Shameless Plug@davetrux

blog.davidtruxall.com

http://bit.ly/androidToIos