Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS for Android Developers (with Swift)

iOS for Android Developers (with Swift)

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.

David Truxall

November 17, 2014
Tweet

More Decks by David Truxall

Other Decks in Programming

Transcript

  1. You • Know Java • Know Android • Don’t know

    Swift • Don’t know iOS • Need a Mac
  2. 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
  3. Swift • Object-oriented AND Functional • C family • Cleaner,

    simpler, safer than Objective-C • Modern features
  4. 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 }
  5. Swift Features • Closures • Tuples and multiple return values

    • Generics • Structs that support methods • Functional programming patterns
  6. 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
  7. 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
  8. Optionals ? - Has a value or no value at

    all (nil) ! - Implicitly Unwrapped Optional
  9. Swift OO class VideoMode { var resolution : Resolution =

    Resolution() var interlaced = false let frameRate = 60.0 var name: String? func setUpMode(modeName: String) -> Void {<do stuff>} }
  10. Swift Functional func 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)
  11. Xcode • Free • It’s an IDE • Click not

    double-click • Virtual file organization
  12. iOS Model - View -Controller ViewController Custom Classes UIView Update

    via IBOutlet Respond to IBAction Update Notify
  13. Lifecycle Events Android iOS onCreate (onCreateView) viewDidLoad onStart viewWillAppear onResume

    viewDidAppear onPause viewWillDisappear onStop viewDidDisappear
  14. UI Elements Android iOS TextView UILabel EditText (single line) UITextField

    EditText (multi-line) UITextView Button UIButton RadioGroup SegmentedControl CheckBox, ToggleButton UISwitch
  15. Delegation • Class has a property that is a protocol

    • Second class implements the protocol • Second class assigned to the variable in the first class
  16. Resources Apple's Swift iBook Swift Developer Center Migrating to Swift

    from Android Book Empty Application template http://bit.ly/androidToIos