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
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
関数型プログラミングのメリットって何だろう?
wanko_it
0
180
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
780
act1-costs.pdf
sumedhbala
0
230
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
170
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
230
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
330
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
140
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
380
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.8k
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
810
Evolving SEO for Evolving Search Engines
ryanjones
0
240
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
How to train your dragon (web standard)
notwaldorf
97
6.7k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
320
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
What's in a price? How to price your products and services
michaelherold
247
13k
How to build a perfect <img>
jonoalderson
1
5.8k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
200
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