SlideShare a Scribd company logo
SWIFT
by Michael Yagudaev
@yagudaev
Outline
• Swift REPL
• Alcatraz (no not the island!)
• Type Safety
• Extendability
• Managing External Dependencies
• Obj-C to Swift and Vice Versa
• Structuring your application
Who Am I
• Rails/Mobile Developer @ Gastown Labs
• Fitness Wearable fanatic…
• Entrepreneur, side project: FitnessKPI
Online Resources
• Swift is very young, there are a few good
resources - just need to find them
NSHipster - posts about iOS Dev and Swift
NSScreencast - similar to railcasts
CodeSchool - Interactive
course to learn Obj-C
Swift REPL
• Run Swift Code from Terminal
• No need to load xCode! (YAY!)
• Similar to IRB, doesn’t have access to application
context
• see the `lldb` expression commands
• (lldb) expr myVar.val()
• http://lldb.llvm.org/lldb-gdb.html
Alcatraz
• xCode sucks. We all know it.
• Alcatraz is a package manager for xCode
(similar to sublime’s package manager)
• Be a hipster, get a dark theme! I use `Sidewalk
Chalk`
Type Safety
• Swift is strongly typed and extremely type safe
• Optionals are variables that can hold a nil value
• In swift, all variables and constants must have a
value, unless they are optional
let PI:Double = 3.14
var twoPI = PI * 2
var sum:Double? = nil
sum = 0
println(sum) // 0
sum = sum + 1 // error! sum is optional
sum = sum! + 1 // works! unwraps optional before addition
var sum:Double = nil // error Double cannot have a nil value!
Type Safety (Cont’d)
• Nil checking is more expressive in Swift
• Chaining optional is a good way to simplify code
• Similar to how things work with CoffeeScript
person.car?.doors[0]?.open()
Extendability
• adding toArray to Range
extension Range {
func toArray() -> [T] {
return [T](self)
}
}
(0...500).toArray()
class Range
def to_array
self.to_a
end
end
(0…500).to_array()
Swift
Ruby
Extendability (cont’d)
• Union of two dictionaries
func + <K,V>(left: Dictionary<K,V>, right: Dictionary<K,V>) -> Dictionary<K,V>
{
var map = Dictionary<K,V>()
for (k, v) in left {
map[k] = v
}
for (k, v) in right {
map[k] = v
}
return map
}
let ab = ["a": 1] + ["b": 2]
class Hash
def +(right)
hash = {}
self.each { |k,v| hash[k] = v }
right.each { |k,v| hash[k] = v }
hash
end
end
ab = {a: 1} + {b: 2}
Swift
Ruby
Extendability WARNING!
PLEASE EXTEND RESPONSIBLY!
Fun Fact
• Swift supports unicode characters for variable
names… (i.e. prank friends using google
translate).
let акулажир = "Shark Fat"
let 瘦鲨⻥鱼 = "skinny Shark"
Managing External
Dependencies
• Most modern languages have the notion of a
package manager. e.g. NPM, Ruby Gems, Bower
• In swift we have Cocoapods… or do we?
• Can only use Cocoapods with Obj-C code (for
now)… :(
• http://www.swifttoolbox.io/ - 

great collection of swift 

packages
Accessing Obj-C from Swift
• Really easy, only need header bridge.h file and
you are set.
“Objective-C is done fool!”
Not quite…
How Obj-C interfaces
Translate to Swift
• Initializers
• Enums
• Unions???
UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero];
let myTableView = UITableView(frame:CGRectZero)
UIButtonType button_type = UIButtonTypeDetailDisclosure;
var buttonType = UIButtonType.DetailDisclosure
How Obj-C interfaces
Translate to Swift (cont’d)
• Unions Obj-C Wrapper
@interface GyroData: NSObject
@property (nonatomic) float x;
@property (nonatomic) float y;
@property (nonatomic) float z;
@end
@implementation GyroData
@end
+ (GyroData *) getGyro:(TLMGyroscopeEvent *)gyroEvent {
GLKVector3 vector = gyroEvent.vector;
GyroData *result = [GyroData new];
result.x = vector.x;
result.y = vector.y;
result.z = vector.z;
return result;
}
let gyroData = GLKitPolyfill.getGyro(gyroEvent)
swift
Accessing Swift Code from
Obj-C
• More difficult, mostly don’t need to do it…
• Uses automatically generated header file
• Add @objc tag to classes and other interfaces
you want to expose to Objective C code.
(CoreData needs this)
Structuring Applications
• No strict directory
structure to iOS apps
• No concept of “folders”
but “groups”, need to
manually keep in sync
• Use the best practices
you learned from Rails
Persistence
• CoreData - if your hardcore like that
• MagicalRecord - ORM for CoreData
• Realm - replacement for CoreData, cross
platform and easier workflow
References
• https://signalvnoise.com/posts/3743
• https://signalvnoise.com/posts/3432-why-i-loved-
building-basecamp-for-iphone-in-rubymotion
• http://realm.io/news/swift-for-rubyists/
• http://www.slideshare.net/josephku/swift-introduction-
to-swift-in-ruby
• http://www.bignerdranch.com/blog/discover-swift-with-
this-one-weird-rubyist/
• http://blog.thefrontiergroup.com.au/2014/09/should-
my-company-choose-rubymotion-or-swift/
• Swift (book)
• Using Swift with Cocoa and Objective-C
QUESTIONS?

More Related Content

What's hot (20)

PDF
Angular 2.0: Brighter future?
Eugene Zharkov
 
PDF
SWIFT1 Optional
Futada Takashi
 
PDF
JavaScript: Patterns, Part 1
Chris Farrell
 
ODP
JavaScript global object, execution contexts & closures
HDR1001
 
PDF
JavaScript Execution Context
Juan Medina
 
PPTX
Javascript ES6
Huy Doan
 
PDF
SE 20016 - programming languages landscape.
Ruslan Shevchenko
 
PDF
Scala e JRuby
mauricioszabo
 
PDF
Swift in SwiftUI
Bongwon Lee
 
PDF
Swift core
Yusuke Kita
 
PPTX
Javascript asynchronous
kang taehun
 
PPTX
OOP in Scala
Roman Melnyk
 
PDF
RubyMotion Introduction
Marc Rendl Ignacio
 
PPTX
Connecting C++ and JavaScript on the Web with Embind
Chad Austin
 
PDF
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PDF
TRICK2015 results
mametter
 
PPTX
C# Today and Tomorrow
Bertrand Le Roy
 
ZIP
拡張ライブラリをD言語で作るとリア充
N Masahiro
 
PDF
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 
Angular 2.0: Brighter future?
Eugene Zharkov
 
SWIFT1 Optional
Futada Takashi
 
JavaScript: Patterns, Part 1
Chris Farrell
 
JavaScript global object, execution contexts & closures
HDR1001
 
JavaScript Execution Context
Juan Medina
 
Javascript ES6
Huy Doan
 
SE 20016 - programming languages landscape.
Ruslan Shevchenko
 
Scala e JRuby
mauricioszabo
 
Swift in SwiftUI
Bongwon Lee
 
Swift core
Yusuke Kita
 
Javascript asynchronous
kang taehun
 
OOP in Scala
Roman Melnyk
 
RubyMotion Introduction
Marc Rendl Ignacio
 
Connecting C++ and JavaScript on the Web with Embind
Chad Austin
 
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
TRICK2015 results
mametter
 
C# Today and Tomorrow
Bertrand Le Roy
 
拡張ライブラリをD言語で作るとリア充
N Masahiro
 
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 

Viewers also liked (10)

PDF
Photography for Equality // Phfe guidelines
Marina Alves
 
PPT
Vanjs backbone-powerpoint
Michael Yagudaev
 
PPTX
Generic Programming &amp; Collection
Arya
 
PPTX
Swift Programming Language Presentation
Agisilaos Tsaraboulidis
 
PDF
Functional Programming 之二三事
Leeheng Ma
 
PDF
Open Source Creativity
Sara Cannon
 
PPSX
Reuters: Pictures of the Year 2016 (Part 2)
maditabalnco
 
PDF
The impact of innovation on travel and tourism industries (World Travel Marke...
Brian Solis
 
PDF
The Outcome Economy
Helge Tennø
 
PDF
The Six Highest Performing B2B Blog Post Formats
Barry Feldman
 
Photography for Equality // Phfe guidelines
Marina Alves
 
Vanjs backbone-powerpoint
Michael Yagudaev
 
Generic Programming &amp; Collection
Arya
 
Swift Programming Language Presentation
Agisilaos Tsaraboulidis
 
Functional Programming 之二三事
Leeheng Ma
 
Open Source Creativity
Sara Cannon
 
Reuters: Pictures of the Year 2016 (Part 2)
maditabalnco
 
The impact of innovation on travel and tourism industries (World Travel Marke...
Brian Solis
 
The Outcome Economy
Helge Tennø
 
The Six Highest Performing B2B Blog Post Formats
Barry Feldman
 
Ad

Similar to Swift for-rubyists (20)

PDF
Swift, swiftly
Jack Nutting
 
PDF
Swift, a quick overview
Julian Król
 
PDF
To Swift 2...and Beyond!
Scott Gardner
 
PDF
Swiftly Switching: The Transition from Obj-C to Swift
Maegan Snee
 
PPTX
Swift vs Objective-C
Mindfire Solutions
 
PDF
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
PDF
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Hossam Ghareeb
 
PDF
Intro toswift1
Jordan Morgan
 
PDF
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
PDF
Денис Лебедев, Swift
Yandex
 
PDF
Swift rocks! #1
Hackraft
 
PDF
Swift Basics
Hirakawa Akira
 
PDF
Denis Lebedev, Swift
Yandex
 
PDF
Objective-C to Swift - Swift Cloud Workshop 3
Randy Scovil
 
PDF
CocoaHeads Bratislava #1 - Swift
EskiMag
 
PDF
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
PDF
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
PDF
Swift after one week of coding
SwiftWro
 
Swift, swiftly
Jack Nutting
 
Swift, a quick overview
Julian Król
 
To Swift 2...and Beyond!
Scott Gardner
 
Swiftly Switching: The Transition from Obj-C to Swift
Maegan Snee
 
Swift vs Objective-C
Mindfire Solutions
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Hossam Ghareeb
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Hossam Ghareeb
 
Intro toswift1
Jordan Morgan
 
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
Jonathan Engelsma
 
Денис Лебедев, Swift
Yandex
 
Swift rocks! #1
Hackraft
 
Swift Basics
Hirakawa Akira
 
Denis Lebedev, Swift
Yandex
 
Objective-C to Swift - Swift Cloud Workshop 3
Randy Scovil
 
CocoaHeads Bratislava #1 - Swift
EskiMag
 
Swift, functional programming, and the future of Objective-C
Alexis Gallagher
 
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
Swift after one week of coding
SwiftWro
 
Ad

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 

Swift for-rubyists

  • 2. Outline • Swift REPL • Alcatraz (no not the island!) • Type Safety • Extendability • Managing External Dependencies • Obj-C to Swift and Vice Versa • Structuring your application
  • 3. Who Am I • Rails/Mobile Developer @ Gastown Labs • Fitness Wearable fanatic… • Entrepreneur, side project: FitnessKPI
  • 4. Online Resources • Swift is very young, there are a few good resources - just need to find them NSHipster - posts about iOS Dev and Swift NSScreencast - similar to railcasts CodeSchool - Interactive course to learn Obj-C
  • 5. Swift REPL • Run Swift Code from Terminal • No need to load xCode! (YAY!) • Similar to IRB, doesn’t have access to application context • see the `lldb` expression commands • (lldb) expr myVar.val() • http://lldb.llvm.org/lldb-gdb.html
  • 6. Alcatraz • xCode sucks. We all know it. • Alcatraz is a package manager for xCode (similar to sublime’s package manager) • Be a hipster, get a dark theme! I use `Sidewalk Chalk`
  • 7. Type Safety • Swift is strongly typed and extremely type safe • Optionals are variables that can hold a nil value • In swift, all variables and constants must have a value, unless they are optional let PI:Double = 3.14 var twoPI = PI * 2 var sum:Double? = nil sum = 0 println(sum) // 0 sum = sum + 1 // error! sum is optional sum = sum! + 1 // works! unwraps optional before addition var sum:Double = nil // error Double cannot have a nil value!
  • 8. Type Safety (Cont’d) • Nil checking is more expressive in Swift • Chaining optional is a good way to simplify code • Similar to how things work with CoffeeScript person.car?.doors[0]?.open()
  • 9. Extendability • adding toArray to Range extension Range { func toArray() -> [T] { return [T](self) } } (0...500).toArray() class Range def to_array self.to_a end end (0…500).to_array() Swift Ruby
  • 10. Extendability (cont’d) • Union of two dictionaries func + <K,V>(left: Dictionary<K,V>, right: Dictionary<K,V>) -> Dictionary<K,V> { var map = Dictionary<K,V>() for (k, v) in left { map[k] = v } for (k, v) in right { map[k] = v } return map } let ab = ["a": 1] + ["b": 2] class Hash def +(right) hash = {} self.each { |k,v| hash[k] = v } right.each { |k,v| hash[k] = v } hash end end ab = {a: 1} + {b: 2} Swift Ruby
  • 12. Fun Fact • Swift supports unicode characters for variable names… (i.e. prank friends using google translate). let акулажир = "Shark Fat" let 瘦鲨⻥鱼 = "skinny Shark"
  • 13. Managing External Dependencies • Most modern languages have the notion of a package manager. e.g. NPM, Ruby Gems, Bower • In swift we have Cocoapods… or do we? • Can only use Cocoapods with Obj-C code (for now)… :( • http://www.swifttoolbox.io/ - 
 great collection of swift 
 packages
  • 14. Accessing Obj-C from Swift • Really easy, only need header bridge.h file and you are set.
  • 15. “Objective-C is done fool!” Not quite…
  • 16. How Obj-C interfaces Translate to Swift • Initializers • Enums • Unions??? UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero]; let myTableView = UITableView(frame:CGRectZero) UIButtonType button_type = UIButtonTypeDetailDisclosure; var buttonType = UIButtonType.DetailDisclosure
  • 17. How Obj-C interfaces Translate to Swift (cont’d) • Unions Obj-C Wrapper @interface GyroData: NSObject @property (nonatomic) float x; @property (nonatomic) float y; @property (nonatomic) float z; @end @implementation GyroData @end + (GyroData *) getGyro:(TLMGyroscopeEvent *)gyroEvent { GLKVector3 vector = gyroEvent.vector; GyroData *result = [GyroData new]; result.x = vector.x; result.y = vector.y; result.z = vector.z; return result; } let gyroData = GLKitPolyfill.getGyro(gyroEvent) swift
  • 18. Accessing Swift Code from Obj-C • More difficult, mostly don’t need to do it… • Uses automatically generated header file • Add @objc tag to classes and other interfaces you want to expose to Objective C code. (CoreData needs this)
  • 19. Structuring Applications • No strict directory structure to iOS apps • No concept of “folders” but “groups”, need to manually keep in sync • Use the best practices you learned from Rails
  • 20. Persistence • CoreData - if your hardcore like that • MagicalRecord - ORM for CoreData • Realm - replacement for CoreData, cross platform and easier workflow
  • 21. References • https://signalvnoise.com/posts/3743 • https://signalvnoise.com/posts/3432-why-i-loved- building-basecamp-for-iphone-in-rubymotion • http://realm.io/news/swift-for-rubyists/ • http://www.slideshare.net/josephku/swift-introduction- to-swift-in-ruby • http://www.bignerdranch.com/blog/discover-swift-with- this-one-weird-rubyist/ • http://blog.thefrontiergroup.com.au/2014/09/should- my-company-choose-rubymotion-or-swift/ • Swift (book) • Using Swift with Cocoa and Objective-C