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
580
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.8k
ARKit + SceneKitでMinesweeperを作ってみた
matuyuji
1
790
Go + QtでiOS アプリ開発
matuyuji
0
390
@_specialized なお話し
matuyuji
0
490
Xcode Souce Code Extensionを使ってみた
matuyuji
0
390
Codebeatを 試してみた
matuyuji
0
780
React Nativeで UIコンポーネントをつくる
matuyuji
0
1k
React Nativeを使ってみた
matuyuji
0
1.3k
SwiftでLens
matuyuji
1
980
Other Decks in Programming
See All in Programming
RailsGirls IZUMO スポンサーLT
16bitidol
0
130
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
260
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
390
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
240
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
570
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
270
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
150
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
170
VS Code Update for GitHub Copilot
74th
1
550
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
250
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
1
330
Featured
See All Featured
Scaling GitHub
holman
459
140k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
720
A better future with KSS
kneath
239
17k
Building Adaptive Systems
keathley
43
2.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Speed Design
sergeychernyshev
32
1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
680
BBQ
matthewcrist
89
9.7k
4 Signs Your Business is Dying
shpigford
184
22k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
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