Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Server Side Swift question
Search
Shinichi Goto
October 21, 2015
3
950
Server Side Swift question
Shinichi Goto
October 21, 2015
Tweet
Share
More Decks by Shinichi Goto
See All by Shinichi Goto
WWDC18 ML Overview
_shingt
1
1.3k
Core ML 🏃 iOS Engineer
_shingt
1
480
Core ML / Vision Frameworkを使ってできること / What can we achieve using Core ML and Vision framework
_shingt
3
4.1k
Wantedly Peopleのスキャン画面の裏側 / Wantedly People Scanning Screen
_shingt
6
6.2k
Providing Better Feedback in Real-time Object Detection Apps
_shingt
2
1.4k
Value Types in WWDC16
_shingt
3
2.5k
debug-remote-local-notification-on-watchos
_shingt
0
10k
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Facilitating Awesome Meetings
lara
50
6.1k
Teambox: Starting and Learning
jrom
133
8.8k
Fireside Chat
paigeccino
34
3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Transcript
Server-Side Swift @_shingt 2015/10/21
[email protected]
#1
Server-Side Swift?????????? @_shingt 2015/10/21
[email protected]
#1
୭ • Software Engineer @ Wantedly, Inc. • Twitter: @_shingt
3
Why Swift on server side • ʢօ͞ΜΕ͔͚ͯͦ͏ͳʣΦʔϓϯιʔεԽ • SwiftͰαʔόαΠυॻ͚ΔͷͰʁͬͯҰॠ Γ্͕ͬͨʢؾ͕͢Δʣ
• ࣄͰSwiftॻ͍ͯͳͯ͘ωλ͕ͳ͍ • ISUCON 4
5 http://isucon.net/
ISUCON • WebΞϓϦέʔγϣϯͷύϑΥʔϚϯεɾ νϡʔχϯάίϯςετʢৄࡉུʣ • ࠓSNSαΠτ͕ࡐ • αʔόαΠυॻ͘ͳΒ࿅शʹஸྑ͍ͷͰ 6
ISUCON • WebΞϓϦέʔγϣϯͷύϑΥʔϚϯεɾ νϡʔχϯάίϯςετʢৄࡉུʣ • ࠓSNSαΠτ͕ࡐ • αʔόαΠυॻ͘ͳΒ࿅शʹஸྑ͍ͷͰ 7 ܸ
To work with server-side app • ࠷ݶ • HTTP Serverʢͱͯ͠ಈ͘ʣ
• Template Engine • DBI, DB driver 8
To work with server-side app • ࠷ݶ • HTTP Server
• Template Engine • DBI, DB driver 9 GRMustache Swifter, Taylor
ͱΓ͋͑ͣ࡞ͬͯΈͯΔͷͰ DEMO https://github.com/shingt/SwiftServerExamples
HTTP server engine / fw • Swifter • ͍ͦͦͬͯ͜͜Δ •
https://github.com/glock45/swifter • Taylor • ͔ͳΓബ͍ & ·ͩػೳἧͬͯͳ͍ • GoͷMartiniϥΠΫʹॻ͚Δ • https://github.com/izqui/Taylor 11
Swifter 12 import Swifter let server = HttpServer() server["/"] =
{ request in return .OK(.HTML("Hello World!")) } var e: NSError? if !server.start(3002, error: &e) { print("Server start error: \(e)") } else { NSRunLoop.mainRunLoop().run() }
Swifter 13 import Swifter let server = HttpServer() server["/"] =
{ request in return .OK(.HTML("Hello World!")) } var e: NSError? if !server.start(3002, error: &e) { print("Server start error: \(e)") } else { NSRunLoop.mainRunLoop().run() }
Taylor 14 import Taylor let server = Taylor.Server() server.get("/") {
req, res, cb in res.bodyString = "Hello World!" cb(.Send(req, res)) } do { try server.serveHTTP(port: 3001, forever: true) } catch let e { print("Server start failed \(e)") }
Taylor 15 import Taylor let server = Taylor.Server() server.get("/") {
req, res, cb in res.bodyString = "Hello World!" cb(.Send(req, res)) } do { try server.serveHTTP(port: 3001, forever: true) } catch let e { print("Server start failed \(e)") }
Swifter or Taylor • ΠϯλʔϑΣΠε Taylor > Swifterʢݸਓత ʹʣ •
͕ɺTaylor·ͩ৭ʑͬͯͳ͍ • Swifter => CarthageରԠͯ͠ͳ͍ • αʔόαΠυతʹѻ͍ʹ͍͘ʁ 16
Swifter or Taylor • ΠϯλʔϑΣΠε Taylor > Swifterʢݸਓత ʹʣ •
͕ɺTaylor·ͩ৭ʑͬͯͳ͍ • Swifter => CarthageରԠͯ͠ͳ͍ • αʔόαΠυతʹѻ͍ʹ͍͘ʁ 17 cocoapods-rome
cocoapods-rome
cocoapods-rome • “pod install” ࣌ʹframeworkΛϏϧυͯ͘͠ΕΔcocoapods plugin • “Swift Scripting” by
Ayaka Nonaka • https://realm.io/jp/news/swift-scripting/ 19
cocoapods-rome 20 platform :osx, '10.10' pod 'Swifter', :git => 'https://
github.com/glock45/swifter.git'
cocoapods-rome 21 platform :osx, '10.10' plugin 'cocoapods-rome' pod 'Swifter', :git
=> 'https:// github.com/glock45/swifter.git'
cocoapods-rome 22 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/
│ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift …
cocoapods-rome 23 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/
│ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift …
cocoapods-rome 24 APP_ROOT ├─ Podfile ├─ Pods/ │ ├─ Headers/
│ ├─ Local Podspecs/ │ ├─ Pods.xcodeproj/ │ ├─ Swifter/ │ ├─ Target Support Files/ │ ├─ Manifest.lock ├─ Rome/ │ └─ Swifter.framework/ ├─ main.swift … swift -F Rome main.swift
ࢥ͏ͱ͜Ζ • ͭΒ͍ ָ͍͠ʂʂʂ • ISUCONղ͜͏ͱͯ͠HTMLϨϯμ͚ͯͨ͠ͲͦͦJSONฦ ͤΕेͳͷͰ… • ॻ͚Δͷͱӡ༻͢ΔͷͱͰ·͕ͨҧ͏͠ઌͦ͏ •
Swift+αʔόαΠυͬΆ͍୯ޠͰݕࡧͯ͠OpenStackͱ͔ RubyͷSwift͕ग़ͯ͘Δ… • cocoapods-romeศར 25
Thank you!