Swift Swiftly A 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?
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? Objective-C without C
What is Swift? Rusty Objective-C#++
What is Swift? Swift IS NOT Objective-C (with new syntax)
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)
Notable Features • Bridges seamlessly to C & Objective-C (mostly)
Notable Features • 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
Optional Types
What are ? 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.
Example
Why Optional Types? • 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. ”
Pattern Matching
What is ? Pattern Matching • No I don’t mean Regular Expressions • Pattern matching in Swift is provided by a switch statement with super powers.
Example
Example
Example
Example
Notable Omissions • Exception handling • Macros • Collections beyond Array & Dictionary • Limited RTTI/Reflection API • Developer definable attributes • No language level support for asynchronous code
Should you learn Swift? Should you learn Swift? YES! (But you should learn Objective-C too.)
Should you deliver in Swift? Should you deliver in Swift? Hell No! (But you should be developing something.)
Thank You. @orj
Recommend
More recommend