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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
230
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
はてなアカウント基盤 State of the Union
cockscomb
0
630
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
Inside Stream API
skrb
1
770
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
Vite+ Unified Toolchain for the Web
naokihaba
0
340
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
120
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
180
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Limits of Empathy - UXLibs8
cassininazir
1
370
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
750
A Tale of Four Properties
chriscoyier
163
24k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Optimizing for Happiness
mojombo
378
71k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
740
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Embracing the Ebb and Flow
colly
88
5.1k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
220
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