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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
matuyuji
July 21, 2015
Programming
630
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift-idl
Swift source code generator from Swift
matuyuji
July 21, 2015
More Decks by matuyuji
See All by matuyuji
Emacs × Touch Bar
matuyuji
2
1.9k
ARKit + SceneKitでMinesweeperを作ってみた
matuyuji
1
830
Go + QtでiOS アプリ開発
matuyuji
0
420
@_specialized なお話し
matuyuji
0
520
Xcode Souce Code Extensionを使ってみた
matuyuji
0
450
Codebeatを 試してみた
matuyuji
0
820
React Nativeで UIコンポーネントをつくる
matuyuji
0
1.1k
React Nativeを使ってみた
matuyuji
0
1.4k
SwiftでLens
matuyuji
1
1.1k
Other Decks in Programming
See All in Programming
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
390
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
110
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
240
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
さぁV100、メモリをお食べ・・・
nilpe
0
140
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
4.9k
Inside Stream API
skrb
1
680
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
150
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
Featured
See All Featured
HDC tutorial
michielstock
2
700
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Thoughts on Productivity
jonyablonski
76
5.2k
Paper Plane (Part 1)
katiecoart
PRO
0
8.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
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