SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
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?

Más contenido relacionado

La actualidad más candente

Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Eugene Zharkov
 
JavaScript: Patterns, Part 1
JavaScript: Patterns, Part  1JavaScript: Patterns, Part  1
JavaScript: Patterns, Part 1Chris Farrell
 
JavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresJavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresHDR1001
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution ContextJuan Medina
 
Javascript ES6
Javascript ES6Javascript ES6
Javascript ES6Huy Doan
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.Ruslan Shevchenko
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUIBongwon Lee
 
Javascript asynchronous
Javascript asynchronousJavascript asynchronous
Javascript asynchronouskang taehun
 
Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindChad Austin
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisRuslan Shevchenko
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
TRICK2015 results
TRICK2015 resultsTRICK2015 results
TRICK2015 resultsmametter
 
拡張ライブラリをD言語で作るとリア充
拡張ライブラリをD言語で作るとリア充拡張ライブラリをD言語で作るとリア充
拡張ライブラリをD言語で作るとリア充N Masahiro
 
Typescript is the best by Maxim Kryuk
Typescript is the best by Maxim KryukTypescript is the best by Maxim Kryuk
Typescript is the best by Maxim KryukGlobalLogic Ukraine
 

La actualidad más candente (20)

Angular 2.0: Brighter future?
Angular 2.0: Brighter future?Angular 2.0: Brighter future?
Angular 2.0: Brighter future?
 
SWIFT1 Optional
SWIFT1 OptionalSWIFT1 Optional
SWIFT1 Optional
 
JavaScript: Patterns, Part 1
JavaScript: Patterns, Part  1JavaScript: Patterns, Part  1
JavaScript: Patterns, Part 1
 
JavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closuresJavaScript global object, execution contexts & closures
JavaScript global object, execution contexts & closures
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution Context
 
Javascript ES6
Javascript ES6Javascript ES6
Javascript ES6
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
Scala e JRuby
Scala e JRubyScala e JRuby
Scala e JRuby
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Swift core
Swift coreSwift core
Swift core
 
Javascript asynchronous
Javascript asynchronousJavascript asynchronous
Javascript asynchronous
 
OOP in Scala
OOP in ScalaOOP in Scala
OOP in Scala
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion Introduction
 
Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with Embind
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
TRICK2015 results
TRICK2015 resultsTRICK2015 results
TRICK2015 results
 
C# Today and Tomorrow
C# Today and TomorrowC# Today and Tomorrow
C# Today and Tomorrow
 
拡張ライブラリをD言語で作るとリア充
拡張ライブラリをD言語で作るとリア充拡張ライブラリをD言語で作るとリア充
拡張ライブラリをD言語で作るとリア充
 
Typescript is the best by Maxim Kryuk
Typescript is the best by Maxim KryukTypescript is the best by Maxim Kryuk
Typescript is the best by Maxim Kryuk
 

Destacado

Photography for Equality // Phfe guidelines
Photography for Equality // Phfe guidelinesPhotography for Equality // Phfe guidelines
Photography for Equality // Phfe guidelinesMarina Alves
 
Generic Programming &amp; Collection
Generic Programming &amp; CollectionGeneric Programming &amp; Collection
Generic Programming &amp; CollectionArya
 
Functional Programming 之二三事
Functional Programming 之二三事Functional Programming 之二三事
Functional Programming 之二三事Leeheng Ma
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source CreativitySara Cannon
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 

Destacado (10)

Photography for Equality // Phfe guidelines
Photography for Equality // Phfe guidelinesPhotography for Equality // Phfe guidelines
Photography for Equality // Phfe guidelines
 
Vanjs backbone-powerpoint
Vanjs backbone-powerpointVanjs backbone-powerpoint
Vanjs backbone-powerpoint
 
Generic Programming &amp; Collection
Generic Programming &amp; CollectionGeneric Programming &amp; Collection
Generic Programming &amp; Collection
 
Swift Programming Language Presentation
Swift Programming Language PresentationSwift Programming Language Presentation
Swift Programming Language Presentation
 
Functional Programming 之二三事
Functional Programming 之二三事Functional Programming 之二三事
Functional Programming 之二三事
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source Creativity
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 

Similar a Swift for-rubyists

Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaScala Italy
 
Денис Лебедев, Swift
Денис Лебедев, SwiftДенис Лебедев, Swift
Денис Лебедев, SwiftYandex
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIDirk Ginader
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the HoodC4Media
 
Swift2 smalltalk osxdev
Swift2 smalltalk osxdevSwift2 smalltalk osxdev
Swift2 smalltalk osxdevJung Kim
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overviewJulian Król
 
Migrating Objective-C to Swift
Migrating Objective-C to SwiftMigrating Objective-C to Swift
Migrating Objective-C to SwiftElmar Kretzer
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsSerge Stinckwich
 
Swift after one week of coding
Swift after one week of codingSwift after one week of coding
Swift after one week of codingSwiftWro
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)David Truxall
 

Similar a Swift for-rubyists (20)

Start with swift
Start with swiftStart with swift
Start with swift
 
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
 
Денис Лебедев, Swift
Денис Лебедев, SwiftДенис Лебедев, Swift
Денис Лебедев, Swift
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the Hood
 
Return of c++
Return of c++Return of c++
Return of c++
 
Rubymotion talk
Rubymotion talkRubymotion talk
Rubymotion talk
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
Swift2 smalltalk osxdev
Swift2 smalltalk osxdevSwift2 smalltalk osxdev
Swift2 smalltalk osxdev
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
Migrating Objective-C to Swift
Migrating Objective-C to SwiftMigrating Objective-C to Swift
Migrating Objective-C to Swift
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
Swift after one week of coding
Swift after one week of codingSwift after one week of coding
Swift after one week of coding
 
Node azure
Node azureNode azure
Node azure
 
About Clack
About ClackAbout Clack
About Clack
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)
 

Último

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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