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 warm up xmlelement
Search
Johnlin
April 03, 2018
Programming
650
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
swift warm up xmlelement
Johnlin
April 03, 2018
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
300
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
390
Ruby 型別檢查工具簡介
johnlinvc
0
620
Swift Actor 實作探索
johnlinvc
0
200
用 mruby 來寫跨平台工具
johnlinvc
0
120
Actor model 簡介
johnlinvc
0
240
一起玩 Helm 3
johnlinvc
1
160
為什麼 App 卡卡的
johnlinvc
2
1.3k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
260
Other Decks in Programming
See All in Programming
霧の中の代数的エフェクト
funnyycat
1
400
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
260
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.3k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
860
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
140
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
650
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
140
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
430
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
520
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
0
280
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
680
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
RailsConf 2023
tenderlove
30
1.5k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
We Are The Robots
honzajavorek
0
280
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
350
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Designing for Timeless Needs
cassininazir
1
370
Claude Code のすすめ
schroneko
67
230k
Transcript
Swift ఔࣜখ XMLElement John Lin
XMLElement • XML จ݅ཫతҰݸ Node, Լ໘ՄҎ༗ߋଟత Node
XML • త૾ HTML ɼෆաੋ፤ိଘࢿྉత • ࠷ۙᔒॄኄਓ༻ • େՈվ༻ json
ྃ
XML ߏ • <aaa> <bbb xxx="yyy"> ccc </bbb> </aaa>
XMLNode • ॴ༗ XML ૬᮫త݁ߏੋṜݸ class త subclass • ՄҎ㗞ੜ֤छ
subclass • ༗ Document, element, attribute, text, comment, namespace, dtd
Nodes • Document: දݸจ݅ɼ။༗Ұݸ root element • Text: Ұஈจࣈ •
attribute: Element తಛੑ • comment: Ḽղ • ଖଞɿᱛᨽ༗᮫(DTD)
㗞ੜXML • <aaa> <bbb xxx="yyy"> ccc </bbb> </aaa> var aaa
= XMLElement(name: "aaa") var bbb = XMLElement(name: "bbb", stringValue: "ccc") aaa.addChild(bbb) bbb.setAttributesWith(["xxx": "yyy"])
ኺXML Ꮣ String • ཁݺڣ String(describing:) print(String(describing: aaa)) <aaa><bbb xxx="yyy">ccc</bbb></aaa>
XMLParser • Delegate based streaming parser. • Delegate based =>
ෆ။ࠂૌ㟬݁Ռɼ။ࠂૌ 㟬ଞ۰౸ྃॄኄ • streaming parser => ෆधཁᩇ౸࠷ޙҰݸࣈ࠽။༗ ݁Ռ • ؆ᄸိ㘸बੋ༻
ࢼ༻ XMLParser let xmlText = """ <swift> <is cool=\"true\"> the
best </is> </swift> """ let data = xmlText.data(using: .utf8) let parser = XMLParser(data: data!)
ࢼ༻ XMLParser @objc class Reader : NSObject, XMLParserDelegate { func
parserDidStartDocument(_ parser: XMLParser) { print("doc started") } func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { print("got elem \(elementName) with attr \ (attributeDict)") } func parser(_ parser: XMLParser, foundCharacters string: String) { print("got value \(string)") } }
ࢼ༻ XMLParser let delegate = Reader() parser.delegate = delegate parser.parse()
output: doc started got elem swift with attr [:] got value got elem is with attr ["cool": "true"] got value the best got value
Plist • Plist ༗ࡾछ ASCII, XML, Binary • Plist ࢧԉ
Codable !!
PropertyListEncoder PropertyListDecoder • ࢧԉ Encode & Decode • ՄҎ༻ Codable
ग़XML Plist struct People : Codable { let name :
String let foods : [String] } let john = People(name: "john", foods: ["pudin", "cake"]) let encoder = PropertyListEncoder() encoder.outputFormat = .xml let encoded = try? encoder.encode(john) print(String(data: encoded!, encoding: .utf8)!) •
ग़XML Plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST
1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>foods</key> <array> <string>pudin</string> <string>cake</string> </array> <key>name</key> <string>john</string> </dict> </plist> •
ࣗగग़త Key struct People : Codable { let name :
String let foods : [String] enum CodingKeys: String, CodingKey { case name = "full_name" case foods } }
ࣗగग़త Key <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST
1.0//EN" "http:// www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>foods</key> <array> <string>pudin</string> <string>cake</string> </array> <key>full_name</key> <string>john</string> </dict> </plist>
ኺ Plist ճ object let decoder = PropertyListDecoder() let another_john
= try? decoder.decode(People.self, from: encoded!) • ။ࣗಈᏗ plist ֨ࣜɼ࠶ data
݁ • XMLElement ᕝ༻త • ཁଘ䈕తؐੋ༻ Codable JSON/Plist 㠧
Q&A
፮ᐔػ • http://slot.miario.com/machines/150067