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
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Side Projects
sachag
452
42k
Embracing the Ebb and Flow
colly
84
4.5k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Bash Introduction
62gerente
608
210k
Building Adaptive Systems
keathley
38
2.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Code Reviewing Like a Champion
maltzj
520
39k
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!