SlideShare a Scribd company logo
Deep Dive Into
Swift
@sarat
Software Architect
A bit of history
Chris Lattner
• Author of the original
LLVM tool chain project
• Started working on Swift
in 2010
• A research intern at
Microsoft Research
• Leads Development Tool
Effort at Apple
Why Swift?
Modern Compilers and
Optimization
Techniques
Influenced by Python,
Ruby, Objective-C, C#
etc.
Productivity
+
Native Performance
easy to learn
Playground & REPL
Playground
REPL (Read-Eval-Print-Loop)
- Write it in lldb when program runs
- Use xcrun swift to run externally
Transparent
interaction with
Objective-C & C
can deploy to previous
version of iOS and OS X
wide adoption in
short time
– The RedMonk Programming Language Rankings: January 2015
“Swift has gone from our 68th ranked
language during Q3 to number 22 this
quarter, a jump of 46 spots.”
Why Swift Performs
better?
Smaller Runtime
generates native
code
Swift Compiler
Architecture
Enumerations
similar to other
languages
enum CompassPoint {
case North
case South
case East
case West
}
enum CompassPoint {
case North
case South
case East
case West
}
var directionToHead = CompassPoint.East;
directionToHead = .East;
enum CompassPoint {
case North
case South
case East
case West
}
var directionToHead = CompassPoint.East;
directionToHead = .East;
switch(directionToHead) {
case .East:
println( "Heading east")
case .West:
println( "Heading West")
case .North:
println( "Heading North")
case .South:
println( "Heading South")
default:
println("Nowhere to go")
}
associated values
Enumerations can store associated
values of any given type.
The type can be different for each
member in the enumeration
// Associated Values Examples
enum Barcode {
case UPCA(Int, Int, Int, Int)
case QRCode(String)
}
// Associated Values Examples
enum Barcode {
case UPCA(Int, Int, Int, Int)
case QRCode(String)
}
var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)
productBarcode = .QRCode("ABCDEFGHIJ")
// Associated Values Examples
enum Barcode {
case UPCA(Int, Int, Int, Int)
case QRCode(String)
}
var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)
productBarcode = .QRCode("ABCDEFGHIJ")
let numberSystem = 8, manufacturer = 85909,
product = 51226, check = 3
switch productBarcode {
case let .UPCA(numberSystem, manufacturer, product, check)
println("UPCA Detected")
case let .QRCode("ABCDEFGHIJ")
println("QRCode detected")
}
switch-case pattern
matching
// Pattern Matching with Switch-Case
let x = 9
switch(x) {
case 1...5: // Closed range operator
println( "Range - 1,2,3,4,5")
case 6..<10: // Half closed range operator
println( "Range - 6,7,8,9")
default:
println("Default")
}
Properties
associates values with
classes, structure or
enumerations
Stored Properties
store constant and
variable values
Lazy Stored Properties
• Initializes on first time access
• Declared with lazy keyword
• Lazy Stored properties can’t be a constant;
for obvious reasons
• Useful when the initial values are depends
on outside factors
// Lazy initialization
class DataImporter {
}
class DataManager {
lazy var importer = DataImporter()
var data = [String]()
}
let m = DataManager()
// importer has not yet been created
m.data.append("Element 1");
m.data.append("Element 2");
m.data.append("Element 3");
// Initialize on first access
m.importer.import();
Computed Properties
computes a value
(rather than store)
// Computed properties
class Rectangle {
var height = 0
var width = 0
var area : Int {
get {
return height * width
}
}
}
Property Observers
// Property Observers
class Temperature {
var current : Int = 26 {
willSet {
println("(newValue)");
// Prints 32
}
didSet {
println("(oldValue)");
// Prints 26
}
}
}
var obj = Temperature()
obj.current = 32;
Override properties
Closures
Self-contained blocks of
functionality that can be
passed around and used in
your code.
Similar to blocks in
Objective-C
Closures
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort({ (a, b) -> Bool in
a < b
})
Closures - Trailing spaces
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort({ (a, b) -> Bool in
a < b
})
Closures - Parentheses
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort { (a, b) -> Bool in
a < b
}
Closures - Type inference
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort { (a, b) -> Bool in
a < b
}
Closures - Type inference
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort { a, b -> Bool in
a < b
}
Closures - Implicit return
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates
cities.sort { a, b in
a < b
}
Closures - Positional
Parameters
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sort with delegates — Positional parameters
cities.sort { $0 < $1 }
Closures - Operator as
closure
// Closures
var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"]
// Sounds interesting?
cities.sort( < )
Optionals
represent possible
missing values
stack.pop?
response.parse().age?
// Age can be nil
var age : Int?
age = response.parse()
Unwrapping
var age : Int?
age = response.parse()
let x = age!
// Your program would crash if you unwrap a nil value
Optional Binding
class Person {
var residence : Residence?
}
class Residence {
var address : Address?
}
class Address {
var buildingNumber : String?
var streetName : String?
var apartmentNumber : String?
}
// Optional Binding
if let home = paul.residence {
if let postalAddress = home.address {
if let building = postalAddress.buildingNumber {
// Code
}
}
}
Optional Chaining
// Optional Chaining
let buildingNumber = paul.residence?.address?.buildingNumber
// optional chaining + bind + unwrap
if let buildingNumber = paul.residence?.address?.buildingNumber {
}
Initializer
Convenience &
Designated Initializers
designated initializers are primary
initializers of a class
a class must have at least one
designated initializer
classes tend to have few
designated initializers
convenience initializers
are secondary; supporting
initializers of a class
class Food {
var name: String
// Designated Initializer
init(name: String) {
self.name = name
}
// Convenience Initializer
convenience init() {
self.init(name: "Unnamed")
}
}
class Food {
var name: String
// Designated Initializer
init(name: String) {
self.name = name
}
// Convenience Initializer
convenience init() {
self.init(name: "Unnamed")
}
}
class Food {
var name: String
// Designated Initializer
init(name: String) {
self.name = name
}
// Convenience Initializer
convenience init() {
self.init(name: "Unnamed")
}
}
overriding
initializers
class Vehicle {
let numberOfWheels = 0
}
class Bicycle : Vehicle {
override init() {
super.init()
numberOfWheels = 2
}
}
class Car : Vehicle {
override init() {
super.init()
numberOfWheels = 4
}
}
class Vehicle {
let numberOfWheels = 0
}
class Bicycle : Vehicle {
override init() {
super.init()
numberOfWheels = 2
}
}
class Car : Vehicle {
override init() {
super.init()
numberOfWheels = 4
}
}
class Vehicle {
let numberOfWheels = 0
}
class Bicycle : Vehicle {
override init() {
super.init()
numberOfWheels = 2
}
}
class Car : Vehicle {
override init() {
super.init()
numberOfWheels = 4
}
}
class Vehicle {
let numberOfWheels = 0
}
class Bicycle : Vehicle {
override init() {
super.init()
numberOfWheels = 2
}
}
class Car : Vehicle {
override init() {
super.init()
numberOfWheels = 4
}
}
Extensions
helps you to attach
functionality data types; even
to the ones you didn’t create!
// Extension as instance method
extension Int {
func plusOne() -> Int {
return self + 1
}
}
var i = 5
i.plusOne()
10.plusOne()
// Extension as instance method
extension Int {
func plusOne() -> Int {
return self + 1
}
}
var i = 5
i.plusOne()
10.plusOne()
// Extension as instance method
extension Int {
func plusOne() -> Int {
return self + 1
}
}
var i = 5
i.plusOne()
10.plusOne()
// Extension as property
extension Double {
var km : Double { return self*1000.0 }
var m : Double { return self }
var cm : Double { return self / 100.0 }
var mm : Double { return self / 10000.0 }
var ft : Double { return self / 3.28084 }
}
let threeFeet = 3.ft // Meters
let oneInch = 25.4.mm // Meters
// Extension as property
extension Double {
var km : Double { return self*1000.0 }
var m : Double { return self }
var cm : Double { return self / 100.0 }
var mm : Double { return self / 10000.0 }
var ft : Double { return self / 3.28084 }
}
let threeFeet = 3.ft // Meters
let oneInch = 25.4.mm // Meters
// Extension as property
extension Double {
var km : Double { return self*1000.0 }
var m : Double { return self }
var cm : Double { return self / 100.0 }
var mm : Double { return self / 10000.0 }
var ft : Double { return self / 3.28084 }
}
let threeFeet = 3.ft // Meters
let oneInch = 25.4.mm // Meters
// Extension as class method
extension UIColor {
class func chilliRed() -> UIColor {
return UIColor(red: 94/255, green: 25/255, blue: 33/255,
alpha: 1)
}
}
var chilliRed = UIColor.chilliRed()
// Extension as class method
extension UIColor {
class func chilliRed() -> UIColor {
return UIColor(red: 94/255, green: 25/255, blue: 33/255,
alpha: 1)
}
}
var chilliRed = UIColor.chilliRed()
// Extension as class method
extension UIColor {
class func chilliRed() -> UIColor {
return UIColor(red: 94/255, green: 25/255, blue: 33/255,
alpha: 1)
}
}
var chilliRed = UIColor.chilliRed()
Protocols &
Delegates
Protocols are
interface definitions
class ViewController: UIViewController, FBLoginViewDelegate {
}
class ViewController: UIViewController, FBLoginViewDelegate {
}
Class
class ViewController: UIViewController, FBLoginViewDelegate {
}
ProtocolClass
protocol LoginProtocol {
func loginSuccessful()
func loginFailed()
}
class ViewController : LoginProtocol {
func loginFailed() {
// code
}
func loginSuccessful() {
// code
}
}
protocol LoginProtocol {
var someProperty : Int { get set }
func loginSuccessful()
func loginFailed()
}
class ViewController : LoginProtocol {
func loginFailed() {
// code
}
func loginSuccessful() {
// code
}
var someProperty : Int = 0 {
willSet {
// Update UI with newValue
}
didSet {
// code
}
}
}
protocol LoginProtocol {
var someProperty : Int { get set }
func loginSuccessful()
func loginFailed()
}
class ViewController : LoginProtocol {
func loginFailed() {
// code
}
func loginSuccessful() {
// code
}
var someProperty : Int = 0 {
willSet {
// Update UI with newValue
}
didSet {
// code
}
}
}
protocol LoginProtocol {
var someProperty : Int { get set }
func loginSuccessful()
func loginFailed()
}
class ViewController : LoginProtocol {
func loginFailed() {
// code
}
func loginSuccessful() {
// code
}
var someProperty : Int = 0 {
willSet {
// Update UI with newValue
}
didSet {
// code
}
}
}
protocol LoginProtocol {
var someProperty : Int { get set }
func loginSuccessful()
func loginFailed()
}
class ViewController : LoginProtocol {
func loginFailed() {
// code
}
func loginSuccessful() {
// code
}
var someProperty : Int = 0 {
willSet {
// Update UI with newValue
}
didSet {
// code
}
}
}
Generics
func swapInt(inout a:Int, inout b:Int) {
let t = a; a = b; b = t
}
func swapString(inout a:String, inout b:String) {
let t = a; a = b; b = t
}
var a = 10, b = 20
swapInt(&a, &b)
var p = "iOS 7", q = "iOS 8"
swapString(&p,&q)
func swapInt(inout a:Int, inout b:Int) {
let t = a; a = b; b = t
}
func swapString(inout a:String, inout b:String) {
let t = a; a = b; b = t
}
var a = 10, b = 20
swapInt(&a, &b)
var p = "iOS 7", q = "iOS 8"
swapString(&p,&q)
// MARK: With Generics
func Swap <T> (inout a: T, inout b: T) {
let t = a; a = b; b = t
}
Swap(&a, &b);
Swap(&p, &q);
func swapInt(inout a:Int, inout b:Int) {
let t = a; a = b; b = t
}
func swapString(inout a:String, inout b:String) {
let t = a; a = b; b = t
}
var a = 10, b = 20
swapInt(&a, &b)
var p = "iOS 7", q = "iOS 8"
swapString(&p,&q)
// MARK: With Generics
func Swap <T> (inout a: T, inout b: T) {
let t = a; a = b; b = t
}
Swap(&a, &b);
Swap(&p, &q);
// Generic Type
struct Stack<T> {
var items = [T]()
mutating func push(item: T) {
items.append(item)
}
mutating func pop() -> T {
return items.removeLast()
}
}
// Stack from somewhere
class Stack<T> {
}
// Extension
extension Stack {
func top() -> T? {
return nil
}
}
// Type constraints
func findIndex<T: Equatable>( array: [T], valueToFind: T) -> Int? {
for(index, value) in enumerate(array) {
if value == valueToFind {
return index
}
}
return nil
}
Mutating
Structures and enumerations are value
types.
By default, the properties of a value type
cannot be modified from within its
instance methods.
// Immutatbility and Mutating
struct Point {
var x = 0.0, y = 0.0
// No change in the actual object
func pointByScaling(factor: Double) -> Point {
return Point(x: self.x*factor, y: self.y*factor)
}
// Function modifies the object
mutating func scale(factor : Double) {
self.x *= factor
self.y *= factor
}
}
// Immutatbility and Mutating
struct Point {
var x = 0.0, y = 0.0
// No change in the actual object
func pointByScaling(factor: Double) -> Point {
return Point(x: self.x*factor, y: self.y*factor)
}
// Function modifies the object
mutating func scale(factor : Double) {
self.x *= factor
self.y *= factor
}
}
// Immutatbility and Mutating
struct Point {
var x = 0.0, y = 0.0
// No change in the actual object
func pointByScaling(factor: Double) -> Point {
return Point(x: self.x*factor, y: self.y*factor)
}
// Function modifies the object
mutating func scale(factor : Double) {
self.x *= factor
self.y *= factor
}
}
Advanced
Operators
struct Vector2D {
var x = 0.0, y = 0.0
}
func + (left:Vector2D, right:Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y + right.y)
}
// Compound Operator
func += (inout left:Vector2D, right:Vector2D) {
left.x += right.x
left.y += right.y
}
var vector = Vector2D(x: 3.0, y: 1.0)
let anotherVector = Vector2D(x: 2.0, y: 4.0)
let combinedVector = vector + anotherVector
vector += anotherVector
struct Vector2D {
var x = 0.0, y = 0.0
}
func + (left:Vector2D, right:Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y + right.y)
}
// Compound Operator
func += (inout left:Vector2D, right:Vector2D) {
left.x += right.x
left.y += right.y
}
var vector = Vector2D(x: 3.0, y: 1.0)
let anotherVector = Vector2D(x: 2.0, y: 4.0)
let combinedVector = vector + anotherVector
vector += anotherVector
struct Vector2D {
var x = 0.0, y = 0.0
}
func + (left:Vector2D, right:Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y + right.y)
}
// Compound Operator
func += (inout left:Vector2D, right:Vector2D) {
left.x += right.x
left.y += right.y
}
var vector = Vector2D(x: 3.0, y: 1.0)
let anotherVector = Vector2D(x: 2.0, y: 4.0)
let combinedVector = vector + anotherVector
vector += anotherVector
struct Vector2D {
var x = 0.0, y = 0.0
}
func + (left:Vector2D, right:Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y + right.y)
}
// Compound Operator
func += (inout left:Vector2D, right:Vector2D) {
left.x += right.x
left.y += right.y
}
var vector = Vector2D(x: 3.0, y: 1.0)
let anotherVector = Vector2D(x: 2.0, y: 4.0)
let combinedVector = vector + anotherVector
vector += anotherVector
struct Vector2D {
var x = 0.0, y = 0.0
}
// Custom operator - Doubling
prefix operator +++ {}
prefix func +++ (inout vector: Vector2D) ->
Vector2D {
vector += vector
return vector
}
let doubled = +++vector
struct Vector2D {
var x = 0.0, y = 0.0
}
// Custom operator - Doubling
prefix operator +++ {}
prefix func +++ (inout vector: Vector2D) ->
Vector2D {
vector += vector
return vector
}
let doubled = +++vector
struct Vector2D {
var x = 0.0, y = 0.0
}
// Custom operator - Doubling
prefix operator +++ {}
prefix func +++ (inout vector: Vector2D) ->
Vector2D {
vector += vector
return vector
}
let doubled = +++vector
operators are only
allowed in global
scope
Using Objective-C
frameworks with Swift
Bridging Header
Demo - FacebookSDK
Integration
References
• The Swift Programming Language - iBooks
• Using Swift with Objective-C and Cocoa -
iBooks
• WWDC 2014 Sessions on Swift
• Developing iOS 8 Apps with Swift -
iTunesU - Stanford

More Related Content

What's hot

Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
Michele Titolo
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
Nikita Popov
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
Bongwon Lee
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik Cube
Manoj Kumar
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
Łukasz Chruściel
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
David de Boer
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
Giuseppe Arici
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
Hugo Firth
 
Learning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a NeckbeardLearning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a Neckbeard
Kelsey Gilmore-Innis
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
Giordano Scalzo
 
Dutch php a short tale about state machine
Dutch php   a short tale about state machineDutch php   a short tale about state machine
Dutch php a short tale about state machine
Łukasz Chruściel
 
C++ L10-Inheritance
C++ L10-InheritanceC++ L10-Inheritance
C++ L10-Inheritance
Mohammad Shaker
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
Ankara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with ScalaAnkara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with Scala
Ensar Basri Kahveci
 
Twig tips and tricks
Twig tips and tricksTwig tips and tricks
Twig tips and tricks
Javier Eguiluz
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
ChengHui Weng
 
One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
John De Goes
 

What's hot (20)

Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik Cube
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Learning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a NeckbeardLearning Functional Programming Without Growing a Neckbeard
Learning Functional Programming Without Growing a Neckbeard
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Dutch php a short tale about state machine
Dutch php   a short tale about state machineDutch php   a short tale about state machine
Dutch php a short tale about state machine
 
C++ L10-Inheritance
C++ L10-InheritanceC++ L10-Inheritance
C++ L10-Inheritance
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Ankara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with ScalaAnkara Jug - Practical Functional Programming with Scala
Ankara Jug - Practical Functional Programming with Scala
 
Twig tips and tricks
Twig tips and tricksTwig tips and tricks
Twig tips and tricks
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
 

Viewers also liked

Swift UI in CloudStack
Swift UI in CloudStackSwift UI in CloudStack
Swift UI in CloudStack
Will Stevens
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)
Ahmed Ali
 
iOS Automation Frameworks evaluation
iOS Automation Frameworks evaluationiOS Automation Frameworks evaluation
iOS Automation Frameworks evaluation
Serghei Moret
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
Sarath C
 
The Swift Programming Language with iOS App
The Swift Programming Language with iOS AppThe Swift Programming Language with iOS App
The Swift Programming Language with iOS App
Mindfire Solutions
 
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Claire Townend Gee
 
tvOS, The Focus Engine, and Swift
tvOS, The Focus Engine, and SwifttvOS, The Focus Engine, and Swift
tvOS, The Focus Engine, and Swift
Evan Maloney
 
iOS 8/Swift 概要 #ios8yahoo
iOS 8/Swift 概要 #ios8yahooiOS 8/Swift 概要 #ios8yahoo
iOS 8/Swift 概要 #ios8yahoo
Hiramatsu Ryosuke
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
Natasha Murashev
 

Viewers also liked (9)

Swift UI in CloudStack
Swift UI in CloudStackSwift UI in CloudStack
Swift UI in CloudStack
 
iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)iOS development using Swift - Swift Basics (2)
iOS development using Swift - Swift Basics (2)
 
iOS Automation Frameworks evaluation
iOS Automation Frameworks evaluationiOS Automation Frameworks evaluation
iOS Automation Frameworks evaluation
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
 
The Swift Programming Language with iOS App
The Swift Programming Language with iOS AppThe Swift Programming Language with iOS App
The Swift Programming Language with iOS App
 
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
 
tvOS, The Focus Engine, and Swift
tvOS, The Focus Engine, and SwifttvOS, The Focus Engine, and Swift
tvOS, The Focus Engine, and Swift
 
iOS 8/Swift 概要 #ios8yahoo
iOS 8/Swift 概要 #ios8yahooiOS 8/Swift 概要 #ios8yahoo
iOS 8/Swift 概要 #ios8yahoo
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 

Similar to Deep Dive Into Swift

Lecture 5
Lecture 5Lecture 5
Lecture 5
Muhammad Fayyaz
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!
John De Goes
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
PowerfullBoy1
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
Abed Bukhari
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Manuel Bernhardt
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
Ralph Johnson
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
Derek Lee Boire
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
Movel
 
Day 1
Day 1Day 1
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
mpnkhan
 
Classes
ClassesClasses
Classes
Swarup Boro
 
A First Date With Scala
A First Date With ScalaA First Date With Scala
A First Date With Scala
Franco Lombardo
 
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum iOS Talks #1 - Swift done right by Ivan DikicInfinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
Yakov Fain
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
SyedHaroonShah4
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
Alfonso Ruzafa
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
JAXLondon_Conference
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
DeepasCSE
 

Similar to Deep Dive Into Swift (20)

Lecture 5
Lecture 5Lecture 5
Lecture 5
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!
 
Unit3_OOP-converted.pdf
Unit3_OOP-converted.pdfUnit3_OOP-converted.pdf
Unit3_OOP-converted.pdf
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Day 1
Day 1Day 1
Day 1
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
Classes
ClassesClasses
Classes
 
A First Date With Scala
A First Date With ScalaA First Date With Scala
A First Date With Scala
 
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum iOS Talks #1 - Swift done right by Ivan DikicInfinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 

Recently uploaded

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 

Recently uploaded (20)

Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 

Deep Dive Into Swift

  • 3. A bit of history
  • 4. Chris Lattner • Author of the original LLVM tool chain project • Started working on Swift in 2010 • A research intern at Microsoft Research • Leads Development Tool Effort at Apple
  • 7. Influenced by Python, Ruby, Objective-C, C# etc.
  • 12. REPL (Read-Eval-Print-Loop) - Write it in lldb when program runs - Use xcrun swift to run externally
  • 14. can deploy to previous version of iOS and OS X
  • 16. – The RedMonk Programming Language Rankings: January 2015 “Swift has gone from our 68th ranked language during Q3 to number 22 this quarter, a jump of 46 spots.”
  • 21.
  • 22.
  • 25. enum CompassPoint { case North case South case East case West }
  • 26. enum CompassPoint { case North case South case East case West } var directionToHead = CompassPoint.East; directionToHead = .East;
  • 27. enum CompassPoint { case North case South case East case West } var directionToHead = CompassPoint.East; directionToHead = .East; switch(directionToHead) { case .East: println( "Heading east") case .West: println( "Heading West") case .North: println( "Heading North") case .South: println( "Heading South") default: println("Nowhere to go") }
  • 29. Enumerations can store associated values of any given type. The type can be different for each member in the enumeration
  • 30. // Associated Values Examples enum Barcode { case UPCA(Int, Int, Int, Int) case QRCode(String) }
  • 31. // Associated Values Examples enum Barcode { case UPCA(Int, Int, Int, Int) case QRCode(String) } var productBarcode = Barcode.UPCA(8, 85909, 51226, 3) productBarcode = .QRCode("ABCDEFGHIJ")
  • 32. // Associated Values Examples enum Barcode { case UPCA(Int, Int, Int, Int) case QRCode(String) } var productBarcode = Barcode.UPCA(8, 85909, 51226, 3) productBarcode = .QRCode("ABCDEFGHIJ") let numberSystem = 8, manufacturer = 85909, product = 51226, check = 3 switch productBarcode { case let .UPCA(numberSystem, manufacturer, product, check) println("UPCA Detected") case let .QRCode("ABCDEFGHIJ") println("QRCode detected") }
  • 34. // Pattern Matching with Switch-Case let x = 9 switch(x) { case 1...5: // Closed range operator println( "Range - 1,2,3,4,5") case 6..<10: // Half closed range operator println( "Range - 6,7,8,9") default: println("Default") }
  • 36. associates values with classes, structure or enumerations
  • 37. Stored Properties store constant and variable values
  • 38. Lazy Stored Properties • Initializes on first time access • Declared with lazy keyword • Lazy Stored properties can’t be a constant; for obvious reasons • Useful when the initial values are depends on outside factors
  • 39. // Lazy initialization class DataImporter { } class DataManager { lazy var importer = DataImporter() var data = [String]() } let m = DataManager() // importer has not yet been created m.data.append("Element 1"); m.data.append("Element 2"); m.data.append("Element 3"); // Initialize on first access m.importer.import();
  • 40. Computed Properties computes a value (rather than store)
  • 41. // Computed properties class Rectangle { var height = 0 var width = 0 var area : Int { get { return height * width } } }
  • 43. // Property Observers class Temperature { var current : Int = 26 { willSet { println("(newValue)"); // Prints 32 } didSet { println("(oldValue)"); // Prints 26 } } } var obj = Temperature() obj.current = 32;
  • 46. Self-contained blocks of functionality that can be passed around and used in your code.
  • 47. Similar to blocks in Objective-C
  • 48. Closures // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort({ (a, b) -> Bool in a < b })
  • 49. Closures - Trailing spaces // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort({ (a, b) -> Bool in a < b })
  • 50. Closures - Parentheses // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort { (a, b) -> Bool in a < b }
  • 51. Closures - Type inference // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort { (a, b) -> Bool in a < b }
  • 52. Closures - Type inference // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort { a, b -> Bool in a < b }
  • 53. Closures - Implicit return // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates cities.sort { a, b in a < b }
  • 54. Closures - Positional Parameters // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sort with delegates — Positional parameters cities.sort { $0 < $1 }
  • 55. Closures - Operator as closure // Closures var cities = ["New Delhi", "Trivandrum", "Kochi", "Bangalore"] // Sounds interesting? cities.sort( < )
  • 59. // Age can be nil var age : Int? age = response.parse()
  • 61. var age : Int? age = response.parse() let x = age! // Your program would crash if you unwrap a nil value
  • 63. class Person { var residence : Residence? } class Residence { var address : Address? } class Address { var buildingNumber : String? var streetName : String? var apartmentNumber : String? }
  • 64. // Optional Binding if let home = paul.residence { if let postalAddress = home.address { if let building = postalAddress.buildingNumber { // Code } } }
  • 66. // Optional Chaining let buildingNumber = paul.residence?.address?.buildingNumber
  • 67. // optional chaining + bind + unwrap if let buildingNumber = paul.residence?.address?.buildingNumber { }
  • 70. designated initializers are primary initializers of a class a class must have at least one designated initializer classes tend to have few designated initializers
  • 71. convenience initializers are secondary; supporting initializers of a class
  • 72. class Food { var name: String // Designated Initializer init(name: String) { self.name = name } // Convenience Initializer convenience init() { self.init(name: "Unnamed") } }
  • 73. class Food { var name: String // Designated Initializer init(name: String) { self.name = name } // Convenience Initializer convenience init() { self.init(name: "Unnamed") } }
  • 74. class Food { var name: String // Designated Initializer init(name: String) { self.name = name } // Convenience Initializer convenience init() { self.init(name: "Unnamed") } }
  • 76. class Vehicle { let numberOfWheels = 0 } class Bicycle : Vehicle { override init() { super.init() numberOfWheels = 2 } } class Car : Vehicle { override init() { super.init() numberOfWheels = 4 } }
  • 77. class Vehicle { let numberOfWheels = 0 } class Bicycle : Vehicle { override init() { super.init() numberOfWheels = 2 } } class Car : Vehicle { override init() { super.init() numberOfWheels = 4 } }
  • 78. class Vehicle { let numberOfWheels = 0 } class Bicycle : Vehicle { override init() { super.init() numberOfWheels = 2 } } class Car : Vehicle { override init() { super.init() numberOfWheels = 4 } }
  • 79. class Vehicle { let numberOfWheels = 0 } class Bicycle : Vehicle { override init() { super.init() numberOfWheels = 2 } } class Car : Vehicle { override init() { super.init() numberOfWheels = 4 } }
  • 81. helps you to attach functionality data types; even to the ones you didn’t create!
  • 82. // Extension as instance method extension Int { func plusOne() -> Int { return self + 1 } } var i = 5 i.plusOne() 10.plusOne()
  • 83. // Extension as instance method extension Int { func plusOne() -> Int { return self + 1 } } var i = 5 i.plusOne() 10.plusOne()
  • 84. // Extension as instance method extension Int { func plusOne() -> Int { return self + 1 } } var i = 5 i.plusOne() 10.plusOne()
  • 85. // Extension as property extension Double { var km : Double { return self*1000.0 } var m : Double { return self } var cm : Double { return self / 100.0 } var mm : Double { return self / 10000.0 } var ft : Double { return self / 3.28084 } } let threeFeet = 3.ft // Meters let oneInch = 25.4.mm // Meters
  • 86. // Extension as property extension Double { var km : Double { return self*1000.0 } var m : Double { return self } var cm : Double { return self / 100.0 } var mm : Double { return self / 10000.0 } var ft : Double { return self / 3.28084 } } let threeFeet = 3.ft // Meters let oneInch = 25.4.mm // Meters
  • 87. // Extension as property extension Double { var km : Double { return self*1000.0 } var m : Double { return self } var cm : Double { return self / 100.0 } var mm : Double { return self / 10000.0 } var ft : Double { return self / 3.28084 } } let threeFeet = 3.ft // Meters let oneInch = 25.4.mm // Meters
  • 88. // Extension as class method extension UIColor { class func chilliRed() -> UIColor { return UIColor(red: 94/255, green: 25/255, blue: 33/255, alpha: 1) } } var chilliRed = UIColor.chilliRed()
  • 89. // Extension as class method extension UIColor { class func chilliRed() -> UIColor { return UIColor(red: 94/255, green: 25/255, blue: 33/255, alpha: 1) } } var chilliRed = UIColor.chilliRed()
  • 90. // Extension as class method extension UIColor { class func chilliRed() -> UIColor { return UIColor(red: 94/255, green: 25/255, blue: 33/255, alpha: 1) } } var chilliRed = UIColor.chilliRed()
  • 93. class ViewController: UIViewController, FBLoginViewDelegate { }
  • 94. class ViewController: UIViewController, FBLoginViewDelegate { } Class
  • 95. class ViewController: UIViewController, FBLoginViewDelegate { } ProtocolClass
  • 96. protocol LoginProtocol { func loginSuccessful() func loginFailed() } class ViewController : LoginProtocol { func loginFailed() { // code } func loginSuccessful() { // code } }
  • 97. protocol LoginProtocol { var someProperty : Int { get set } func loginSuccessful() func loginFailed() } class ViewController : LoginProtocol { func loginFailed() { // code } func loginSuccessful() { // code } var someProperty : Int = 0 { willSet { // Update UI with newValue } didSet { // code } } }
  • 98. protocol LoginProtocol { var someProperty : Int { get set } func loginSuccessful() func loginFailed() } class ViewController : LoginProtocol { func loginFailed() { // code } func loginSuccessful() { // code } var someProperty : Int = 0 { willSet { // Update UI with newValue } didSet { // code } } }
  • 99. protocol LoginProtocol { var someProperty : Int { get set } func loginSuccessful() func loginFailed() } class ViewController : LoginProtocol { func loginFailed() { // code } func loginSuccessful() { // code } var someProperty : Int = 0 { willSet { // Update UI with newValue } didSet { // code } } }
  • 100. protocol LoginProtocol { var someProperty : Int { get set } func loginSuccessful() func loginFailed() } class ViewController : LoginProtocol { func loginFailed() { // code } func loginSuccessful() { // code } var someProperty : Int = 0 { willSet { // Update UI with newValue } didSet { // code } } }
  • 102. func swapInt(inout a:Int, inout b:Int) { let t = a; a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q)
  • 103. func swapInt(inout a:Int, inout b:Int) { let t = a; a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q) // MARK: With Generics func Swap <T> (inout a: T, inout b: T) { let t = a; a = b; b = t } Swap(&a, &b); Swap(&p, &q);
  • 104. func swapInt(inout a:Int, inout b:Int) { let t = a; a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q) // MARK: With Generics func Swap <T> (inout a: T, inout b: T) { let t = a; a = b; b = t } Swap(&a, &b); Swap(&p, &q);
  • 105. // Generic Type struct Stack<T> { var items = [T]() mutating func push(item: T) { items.append(item) } mutating func pop() -> T { return items.removeLast() } }
  • 106. // Stack from somewhere class Stack<T> { } // Extension extension Stack { func top() -> T? { return nil } }
  • 107. // Type constraints func findIndex<T: Equatable>( array: [T], valueToFind: T) -> Int? { for(index, value) in enumerate(array) { if value == valueToFind { return index } } return nil }
  • 109. Structures and enumerations are value types. By default, the properties of a value type cannot be modified from within its instance methods.
  • 110. // Immutatbility and Mutating struct Point { var x = 0.0, y = 0.0 // No change in the actual object func pointByScaling(factor: Double) -> Point { return Point(x: self.x*factor, y: self.y*factor) } // Function modifies the object mutating func scale(factor : Double) { self.x *= factor self.y *= factor } }
  • 111. // Immutatbility and Mutating struct Point { var x = 0.0, y = 0.0 // No change in the actual object func pointByScaling(factor: Double) -> Point { return Point(x: self.x*factor, y: self.y*factor) } // Function modifies the object mutating func scale(factor : Double) { self.x *= factor self.y *= factor } }
  • 112. // Immutatbility and Mutating struct Point { var x = 0.0, y = 0.0 // No change in the actual object func pointByScaling(factor: Double) -> Point { return Point(x: self.x*factor, y: self.y*factor) } // Function modifies the object mutating func scale(factor : Double) { self.x *= factor self.y *= factor } }
  • 114. struct Vector2D { var x = 0.0, y = 0.0 } func + (left:Vector2D, right:Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y) } // Compound Operator func += (inout left:Vector2D, right:Vector2D) { left.x += right.x left.y += right.y } var vector = Vector2D(x: 3.0, y: 1.0) let anotherVector = Vector2D(x: 2.0, y: 4.0) let combinedVector = vector + anotherVector vector += anotherVector
  • 115. struct Vector2D { var x = 0.0, y = 0.0 } func + (left:Vector2D, right:Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y) } // Compound Operator func += (inout left:Vector2D, right:Vector2D) { left.x += right.x left.y += right.y } var vector = Vector2D(x: 3.0, y: 1.0) let anotherVector = Vector2D(x: 2.0, y: 4.0) let combinedVector = vector + anotherVector vector += anotherVector
  • 116. struct Vector2D { var x = 0.0, y = 0.0 } func + (left:Vector2D, right:Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y) } // Compound Operator func += (inout left:Vector2D, right:Vector2D) { left.x += right.x left.y += right.y } var vector = Vector2D(x: 3.0, y: 1.0) let anotherVector = Vector2D(x: 2.0, y: 4.0) let combinedVector = vector + anotherVector vector += anotherVector
  • 117. struct Vector2D { var x = 0.0, y = 0.0 } func + (left:Vector2D, right:Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y) } // Compound Operator func += (inout left:Vector2D, right:Vector2D) { left.x += right.x left.y += right.y } var vector = Vector2D(x: 3.0, y: 1.0) let anotherVector = Vector2D(x: 2.0, y: 4.0) let combinedVector = vector + anotherVector vector += anotherVector
  • 118. struct Vector2D { var x = 0.0, y = 0.0 } // Custom operator - Doubling prefix operator +++ {} prefix func +++ (inout vector: Vector2D) -> Vector2D { vector += vector return vector } let doubled = +++vector
  • 119. struct Vector2D { var x = 0.0, y = 0.0 } // Custom operator - Doubling prefix operator +++ {} prefix func +++ (inout vector: Vector2D) -> Vector2D { vector += vector return vector } let doubled = +++vector
  • 120. struct Vector2D { var x = 0.0, y = 0.0 } // Custom operator - Doubling prefix operator +++ {} prefix func +++ (inout vector: Vector2D) -> Vector2D { vector += vector return vector } let doubled = +++vector
  • 121. operators are only allowed in global scope
  • 124.
  • 126. References • The Swift Programming Language - iBooks • Using Swift with Objective-C and Cocoa - iBooks • WWDC 2014 Sessions on Swift • Developing iOS 8 Apps with Swift - iTunesU - Stanford