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
490
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
Done Done
chrislema
181
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Statistics for Hackers
jakevdp
796
220k
Optimising Largest Contentful Paint
csswizardry
33
3k
Become a Pro
speakerdeck
PRO
26
5k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Building Adaptive Systems
keathley
38
2.3k
GraphQLとの向き合い方2022年版
quramy
44
13k
Automating Front-end Workflow
addyosmani
1366
200k
Six Lessons from altMBA
skipperchong
27
3.5k
Making Projects Easy
brettharned
116
5.9k
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!