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
290
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
380
Ruby 型別檢查工具簡介
johnlinvc
0
610
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
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.5k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
13
6.2k
Webフレームワークの ベンチマークについて
yusukebe
0
180
Inside Stream API
skrb
1
770
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
140
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
2
730
Performance Engineering for Everyone
elenatanasoiu
0
210
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
スマートグラスで並列バイブコーディング
hyshu
0
260
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
さぁV100、メモリをお食べ・・・
nilpe
0
150
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
エンジニアに許された特別な時間の終わり
watany
107
250k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
240
Testing 201, or: Great Expectations
jmmastey
46
8.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Designing Experiences People Love
moore
143
24k
How to train your dragon (web standard)
notwaldorf
97
6.7k
YesSQL, Process and Tooling at Scale
rocio
174
15k
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