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
940
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.2k
Core ML 🏃 iOS Engineer
_shingt
1
480
Core ML / Vision Frameworkを使ってできること / What can we achieve using Core ML and Vision framework
_shingt
3
4k
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
How GitHub (no longer) Works
holman
311
140k
Practical Orchestrator
shlominoach
186
10k
Six Lessons from altMBA
skipperchong
26
3.5k
Thoughts on Productivity
jonyablonski
67
4.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Speed Design
sergeychernyshev
24
570
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Rails Girls Zürich Keynote
gr2m
93
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Making Projects Easy
brettharned
115
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!