iOS for Android Developers (with Swift)

  • View
    2.074

  • Download
    1

  • Category

    Software

Preview:

DESCRIPTION

As an app developer there is always pressure to understand and be able to address both major platforms. At first blush, coding for iOS seems quite different than for Android, perhaps due to the language differences between Objective-C and Java, and of course there is a different IDE and framework. With the introduction of Swift, this chasm seems much smaller. This talk will map Android and Java functionality to similar concepts in iOS using Swift. We’ll see the similarities and differences, focusing on framework concepts, and migrate a simple Android app to iOS.

Citation preview

iOS for Android Developers

with Swift

David Truxall, Ph.D.

http://bit.ly/androidToIos

About Me@davetrux

blog.davidtruxall.com

You

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

Goal

Learn basic iOS concepts for someone

familiar with Android

(using 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

Agenda

1. Brief language intro

2. Project/Tool Structure

3. App Architecture

4. Coding Demo

Swift

● Object-oriented AND Functional

● C family

● Cleaner, simpler, safer than Objective-C

● Modern features

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

}

Swift Features

● Closures

● Tuples and multiple return values

● Generics

● Structs that support methods

● Functional programming patterns

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

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

Optionals

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

! - Implicitly Unwrapped Optional

Swift OOclass VideoMode {

var resolution : Resolution = Resolution()

var interlaced = false

let frameRate = 60.0

var name: String?

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

}

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)

Xcode

● Free

● It’s an IDE

● Click not double-click

● Virtual file organization

Demo

Application Architecture

Model - View - Controller

UI Organization and Plumbing

Model - View -Controller

Controller

ModelView

Update

User Action

Update

Notify

Android != Model-View-Controller

Activity

ProviderLayout

Update

Notify

iOS Model - View -Controller

ViewController

Custom ClassesUIView

Update via IBOutlet

Respond to IBAction

Update

Notify

UI Organization

Android iOS

Layout XML XIB (NIB)

- Storyboard

- IBOutlet

- IBAction

Intent ~ Segue

Lifecycle EventsAndroid iOS

onCreate (onCreateView) viewDidLoad

onStart viewWillAppear

onResume viewDidAppear

onPause viewWillDisappear

onStop viewDidDisappear

UI ElementsAndroid iOS

TextView UILabel

EditText (single line) UITextField

EditText (multi-line) UITextView

Button UIButton

RadioGroup SegmentedControl

CheckBox, ToggleButton UISwitch

Delegation

● Class has a property that is a protocol

● Second class implements the protocol

● Second class assigned to the variable in

the first class

Converting an App

Yet Another Shameless Plug@davetrux

blog.davidtruxall.com

http://bit.ly/androidToIos