Swift SwiftlyA quick introduction to the Swift language
Oliver Jones Technical Director
Disclaimer
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
What is Swift?
• 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?
What is Swift?
Objective-C without C
Rusty Objective-C#++
What is Swift?
Swift IS NOT
Objective-C (with new syntax)
What is Swift?
Swift Code
What is Swift?
• 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?
Notable Features
• Bridges seamlessly to C & Objective-C (mostly)
What is Swift?
• Type Inference & Explicitly mutable/immutable variables.
Notable Features
• Generics
Notable Features
• Operator Overloading
Notable Features
• Classes/Reference Types (objects) & Value Types (structs, enums)
Notable Features
• First Class Functions & Closures
Notable Features
• Tuples
Notable Features
• Type Extensions
Notable Features
Optional Types
• 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
Example
• 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?
Pattern Matching
What is ?
• No I don’t mean Regular Expressions
• Pattern matching in Swift is provided by a switch statement with super powers.
Pattern Matching
Example
Example
Example
Example
• Exception handling
• Macros
• Collections beyond Array & Dictionary
• Limited RTTI/Reflection API
• Developer definable attributes
• No language level support for asynchronous code
Notable Omissions
(But you should learn Objective-C too.)
Should you learn Swift?
YES!Should you learn Swift?
(But you should be developing something.)
Should you deliver in Swift?
Hell No!Should you deliver in Swift?
Thank You.
@orj