Slide 1

Slide 1 text

A Swift Introduction To Swift by @neilkimmett

Slide 2

Slide 2 text

Swift is a type safe language

Slide 3

Slide 3 text

Types Javascript "1" + 2 = "12" Ruby x = 5 x = "a string" x = Dog.new

Slide 4

Slide 4 text

Types Swift "1" + 2

Slide 5

Slide 5 text

Types Swift var x = 5 x = "a string"

Slide 6

Slide 6 text

Types let number: Int = 2 let name: String = "Sup Codebar" let primes: [Int] = [2, 3, 5, 7, 11] let view: UIView = UIView() view.backgroundColor = UIColor.whiteColor()

Slide 7

Slide 7 text

✨ Type inference ✨ let number = 2 let name = "Sup Codebar" let primes = [2, 3, 5, 7, 11] let view = UIView() view.backgroundColor = .whiteColor()

Slide 8

Slide 8 text

Constants & variables let words = "Hello, there" words = "Bye for now"

Slide 9

Slide 9 text

Constants & variables let words = "Hello, there" words = "Bye for now"

Slide 10

Slide 10 text

Constants & variables let words = "Hello, there" words = "Bye for now"

Slide 11

Slide 11 text

Constants & variables var words = "Hello, there" words = "Bye for now"

Slide 12

Slide 12 text

Functions func multiply(array: [Int], by: Int) -> [Int]

Slide 13

Slide 13 text

Functions func multiply(array: [Int], by: Int) -> [Int] { var result = [Int]() for x in array { result.append(x * by) } return result }

Slide 14

Slide 14 text

Functions func multiply(array: [Int], by: Int) -> [Int] { return array.map({ (x) -> Int in return x * by }) }

Slide 15

Slide 15 text

Functions func multiply(array: [Int], by: Int) -> [Int] { return array.map { $0 * by } }

Slide 16

Slide 16 text

Functions func multiply(array: [Int], by: Int) -> [Int] { return array.map { $0 * by } } multiply(array: numbers, by: 2)

Slide 17

Slide 17 text

Classes class Counter { private var count = 0 func increment() { count += 1 } } let counter = Counter() counter.increment()

Slide 18

Slide 18 text

Optionals?!

Slide 19

Slide 19 text

Optionals class Codebar { var location: String = "Pivotal Labs, EC1V 9NR" } let codebar = Codebar() // insert lots of awesome talks here codebar.location = "The pub" // insert lots of inspiring conversations here codebar.location = nil !

Slide 20

Slide 20 text

?

Slide 21

Slide 21 text

Optionals class Codebar { var location: String? = "Pivotal Labs, EC1V 9NR" } let codebar = Codebar() // stuff codebar.location = nil !

Slide 22

Slide 22 text

Other super awesome stuff • structs • enums • protocols • generics •  frameworks

Slide 23

Slide 23 text

Further reading • "The Swift Programming Language" by Apple • raywenderlich.com • swift.org • WWDC videos • IBM Swift Sandbox • Swift Playgrounds for iPad on iOS 10

Slide 24

Slide 24 text

Thanks ! @neilkimmett " [email protected] # kimmett.me