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.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
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Code Reviewing Like a Champion
maltzj
520
39k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Practical Orchestrator
shlominoach
186
10k
Speed Design
sergeychernyshev
24
610
Teambox: Starting and Learning
jrom
133
8.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Documentation Writing (for coders)
carmenintech
65
4.4k
What's in a price? How to price your products and services
michaelherold
243
12k
How STYLIGHT went responsive
nonsquared
95
5.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!