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
Swift-idl
Search
matuyuji
July 21, 2015
Programming
0
520
Swift-idl
Swift source code generator from Swift
matuyuji
July 21, 2015
Tweet
Share
More Decks by matuyuji
See All by matuyuji
Emacs × Touch Bar
matuyuji
2
1.6k
ARKit + SceneKitでMinesweeperを作ってみた
matuyuji
1
750
Go + QtでiOS アプリ開発
matuyuji
0
350
@_specialized なお話し
matuyuji
0
450
Xcode Souce Code Extensionを使ってみた
matuyuji
0
310
Codebeatを 試してみた
matuyuji
0
650
React Nativeで UIコンポーネントをつくる
matuyuji
0
960
React Nativeを使ってみた
matuyuji
0
1.2k
SwiftでLens
matuyuji
1
890
Other Decks in Programming
See All in Programming
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
180
[SF Ruby, March 2024] Rails on Wasm
palkan
0
380
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
160
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
3.6k
코틀린으로 멀티플랫폼 만들기
pangmoo
0
120
Doctrine ORMでValue Objectを扱う方法4選 #phpstudy / 4 ways to handle Value Objects with Doctrine ORM
77web
4
110
Folding Cheat Sheet #3
philipschwarz
PRO
0
110
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
480
元気予報
suu_mire0726
0
860
PostmanでAPIの動作確認が楽になった話
h455h1
0
130
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
250
Featured
See All Featured
How to name files
jennybc
64
92k
Being A Developer After 40
akosma
56
580k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
29
6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
76
41k
Rails Girls Zürich Keynote
gr2m
91
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
9
8.3k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
Web development in the modern age
philhawksworth
202
10k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Git: the NoSQL Database
bkeepers
PRO
422
63k
Transcript
swift-idl @matuyuji ؔϞόΠϧΞϓϦݚڀձ #4 2015.7.21
@matuyuji safx-dev.blogspot.jp
JSON Libraries • Himotoki • Decodable • Argo • JSONHelper
• ObjectMapper
Decodable struct FileEntry { let fileName: String let size: Int
} extension FileEntry: Decodable { static func decode(j: AnyObject) throws -> FileEntry { return try Repository( fileName: j => “file-name", size: j => "size", ) } }
• DRYత͡Όͳ͍ • JSONϥΠϒϥϦ͕ཉ͍͠Θ͚͡Όͳ͍
Golang type FileEntry struct { FileName string `json:"file-name"` Size int
`json:"size"` }
ཉ͍͠ͷ • REST APIΫϥΠΞϯτΛָʹߏங͍ͨ͠ • DRYతͳͷ
safx/swift-idl struct FileEntry: JSONDecodable, JSONEncodable, Printable { let fileName: String
// json:"file-name" let size : Int } python swift-idl.py MyProj.xcodeproj
public struct FileEntry: JSONDecodable, JSONEncodable, CustomStringConvertible { public let fileName:
String // json:"file-name" public let size : Int public static func parseJSON(data: AnyObject) throws -> FileEntry { if !(data is NSDictionary) { throw JSONDecodeError.TypeMismatch(key: "FileEntry", type: "NSDictionary") } let fileName: String if let v: AnyObject = data["file-name"] { if v is NSNull { throw JSONDecodeError.NonNullablle(key: "file-name") } else { do { fileName = try String.parseJSON(v) } catch JSONDecodeError.ValueTranslationFailed { throw JSONDecodeError.TypeMismatch(key: "file-name", type: "String") } } } else { throw JSONDecodeError.MissingKey(key: "file-name") } let size: Int if let v: AnyObject = data["size"] { if v is NSNull { throw JSONDecodeError.NonNullablle(key: "size") } else { do { size = try Int.parseJSON(v) } catch JSONDecodeError.ValueTranslationFailed { throw JSONDecodeError.TypeMismatch(key: "size", type: "Int") }
Protocols protocol Printable {} protocol NSCoding {} protocol JSONEncodable {}
protocol JSONDecodable {} protocol URLRequestHelper {} protocol ClassInit {} protocol EnumStaticInit {}
URLRequestHelper enum Router: URLRequestHelper { case GetProfile // router:",profile" case
GetMessages(topicId: TopicID, // router:"GET,topics/\(topicId)" count: Int?) case PostMessage(topicId: TopicID, // router:"POST,topics/\(topicId)" message: String, replyTo: Int?) }
public enum Router { case GetProfile case GetMessages(topicId: TopicID, count:
Int?) case PostMessage(topicId: TopicID, message: String, replyTo: Int?) public var method: String { switch self { case .GetProfile: return "GET" case .GetMessages: return "GET" case .PostMessage: return "POST" } } public var path: String { switch self { case .GetProfile: return "profile" case .GetMessages(let (topicId, _)): return "topics/\(topicId)" case .PostMessage(let (topicId, _, _)): return "topics/\(topicId)" } } public var params: [String: AnyObject] { switch self { case .GetProfile: return [:] case .GetMessages(let (_, count)): var p: [String: AnyObject] = [:] count.map { p["count"] = $0.toJSON() } return p case .PostMessage(let (_, message, replyTo)): var p: [String: AnyObject] = ["message": message.toJSON()] replyTo.map { p["replyTo"] = $0.toJSON() } return p } } }
Install & Setting • brew install sourcekitten • github clone
https://github.com/safx/swift-idl.git TypetalkKit swift-2.0 Xcode 6.4 Xcode 7