We have this new language, Swift, which takes some familiar Apple patterns, and introduces some new ones. With tools like closures and method chaining, there are definitely some new ways to solve the age-old Obj-c architecture challenges. This talk will walk through some of the most common Obj-c design patterns rewritten in Swift, and showcase the strengths and weaknesses of this new language.
45. class Car {
let numWheels: Int
let numCylinders: Int
init (numWheels: Int, numCylinders: Int) {
self.numWheels = numWheels
self.numCylinders = numCylinders
}
}
var newCar = Car(numWheels: 4,numCylinders: 4)
var otherCar = Car(numWheels: 4, numCylinders: 6)
54. struct WheelSet {
var wheelSize: Int
var wheelFrictionCoefficient: Float
}
struct BodyType {
var numWheels: Int
var wheels: WheelSet
var wheelBase: Float
}
enum EngineType: Int {
case Automatic, Manual
}
protocol Vehicle {
var body: BodyType {get set}
var transmission: EngineType {get set}
func drive(force: Float)
func turn(speed: Float)
}
104. More Swift!
• Today 11:30am
Interoperating Swift with Lower Level Code
by Stephan Tramer in Terrace
• Tomorrow 1:45pm
Functional Programming in Swift
by Chris Eidhof in Vail
105. Resources
• Swift Programming Guide from Apple
• Design Patterns in Dynamic Programming by Peter
Norvig
• Erica Sadun’s many blog posts on Swift
• Functional Programming in Swift, ebook by Objc.io
founders (See Chris’ talk tomorrow!)
• Instance Methods and Curried Functions in Swift by Ole
Begemann