Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of...

32
Swift Swiftly A quick introduction to the Swift language Oliver Jones Technical Director

Transcript of Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of...

Page 1: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Swift SwiftlyA quick introduction to the Swift language

Oliver Jones Technical Director

Page 2: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Disclaimer

Page 3: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Learning Swift

• iBooks

• The Swift Programming Language

• Using Swift with Cocoa and Objective-C

• Apple Developer Documentation

• WWDC 2014 Videos

• Apple Developer Forums

• Blogs, Github, Stack Overflow, etc

Page 4: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

What is Swift?

Page 5: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• A new programming language introduced at Apple’s WWDC 2014 in June

• Designed/Created by Chris Lattner

• Apple Developer Tools department Director and Architect

• LLVM compiler project founder

What is Swift?

Page 6: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

What is Swift?

Objective-C without C

Page 7: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Rusty Objective-C#++

What is Swift?

Page 8: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Swift IS NOT

Objective-C (with new syntax)

What is Swift?

Page 9: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Swift Code

What is Swift?

Page 10: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Native (x86 & ARM), Compiled

• Strongly Typed

• Designed for OS X and iOS developers

• Intended to eventually replace Objective-C

• Closed source (for now)

What is Swift?

Page 11: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Notable Features

• Bridges seamlessly to C & Objective-C (mostly)

What is Swift?

Page 12: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Type Inference & Explicitly mutable/immutable variables.

Notable Features

Page 13: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Generics

Notable Features

Page 14: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Operator Overloading

Notable Features

Page 15: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Classes/Reference Types (objects) & Value Types (structs, enums)

Notable Features

Page 16: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• First Class Functions & Closures

Notable Features

Page 17: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Tuples

Notable Features

Page 18: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Type Extensions

Notable Features

Page 19: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Optional Types

Page 20: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• By default variables in Swift must be initialised with a value.

• Optional types allow those variables to be assigned a nil value.

• This applies to variables of any type not just object references.

What are ?Optional Types

Page 21: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Example

Page 22: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Tony Hoare’s Billion Dollar Mistake

• Creator of QuickSort and ALGOL W

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

Why Optional Types?

Page 23: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Pattern Matching

Page 24: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

What is ?

• No I don’t mean Regular Expressions

• Pattern matching in Swift is provided by a switch statement with super powers.

Pattern Matching

Page 25: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Example

Page 26: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Example

Page 27: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Example

Page 28: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Example

Page 29: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

• Exception handling

• Macros

• Collections beyond Array & Dictionary

• Limited RTTI/Reflection API

• Developer definable attributes

• No language level support for asynchronous code

Notable Omissions

Page 30: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

(But you should learn Objective-C too.)

Should you learn Swift?

YES!Should you learn Swift?

Page 31: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

(But you should be developing something.)

Should you deliver in Swift?

Hell No!Should you deliver in Swift?

Page 32: Swift Swiftly - YOW! Conferences · • Tony Hoare’s Billion Dollar Mistake • Creator of QuickSort and ALGOL W I call it my billion-dollar mistake. It was the invention of the

Thank You.

@orj