Slide 1

Slide 1 text

20.01.2016 Forget Objective-C. Start Swift. for Kharkiv Mobile Devs #15

Slide 2

Slide 2 text

Alexey Demedetskiy ✤ twitter: @DAlooG ✤ email: [email protected] ✤ skype: nobidon

Slide 3

Slide 3 text

Objective-C ✤ KVO/KVC ✤ UIKit ✤ Monolithic namespace ✤ Partially defined behavior ✤ CoreData

Slide 4

Slide 4 text

Swift ✤ Closures ✤ Immutability ✤ Value types ✤ Generics ✤ Optionals

Slide 5

Slide 5 text

Swift ✤ Protocols ✤ Nested types ✤ Static ✤ Default values ✤ Operators

Slide 6

Slide 6 text

How to Swift? ✤ Add Swift to existing project ✤ Start new project

Slide 7

Slide 7 text

Why? ✤ Strong types —> Less errors ✤ More instruments —> Cleaner code ✤ Better syntax —> Easy to read and write

Slide 8

Slide 8 text

Optionals vs ‘nil’

Slide 9

Slide 9 text

nil ✤ [nil aMessage:@«text»] - ✅ ✤ [list addObject:nil] - ❌

Slide 10

Slide 10 text

Optional ✤ T! ✤ T? ✤ T

Slide 11

Slide 11 text

Dirty Types ✤ UIKit ✤ External data (Network etc) ✤ Objective-C

Slide 12

Slide 12 text

How to clear types? ✤ as? : Any -> T? ✤ as! : Any -> T

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

WTF Immutability. ✤ Reference and Value types ✤ let - immutable name ✤ var - mutable name

Slide 17

Slide 17 text

Struct trickery ✤ How many objects will be created? ✤ How many times `print` will write? ✤ What `t1.b` will print?

Slide 18

Slide 18 text

Struct trickery ✤ 0. There is no objects. ✤ 1. ✤ 4.

Slide 19

Slide 19 text

Class trickery ✤ How many objects will be created? ✤ How many times `print` will write? ✤ What `t1.b` will print?

Slide 20

Slide 20 text

Class trickery ✤ 1 ✤ 1 ✤ -1

Slide 21

Slide 21 text

let == const?

Slide 22

Slide 22 text

let == const?

Slide 23

Slide 23 text

Value types Pros ✤ Immutable. Even with `var` ✤ `init` from compiler ✤ No inheritance

Slide 24

Slide 24 text

Properties ✤ no setter / getter methods. ✤ …unless `dynamic` is specified ✤ `willSet` / `didSet` with references to new/old values ✤ `public private(set) var …` is ok

Slide 25

Slide 25 text

enum vs NS_ENUM

Slide 26

Slide 26 text

enum vs NS_ENUM

Slide 27

Slide 27 text

Shadow types!

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

When use enum? ✤ Flags ✤ States ✤ Options ✤ Shadow type

Slide 31

Slide 31 text

Alamofire vs AFNetworking

Slide 32

Slide 32 text

Namespaces ✤ Nested types ✤ Frameworks ✤ Targets

Slide 33

Slide 33 text

Nested types

Slide 34

Slide 34 text

Nested types

Slide 35

Slide 35 text

Nested types

Slide 36

Slide 36 text

Nested types

Slide 37

Slide 37 text

Nested types

Slide 38

Slide 38 text

let = vs dispatch_once

Slide 39

Slide 39 text

Outro ✤ Run away from Obj-C ✤ Build your own logic modules ✤ Use Value Types ✤ Don’t use generics + inheritance + UIKit