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
310
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
400
Ruby 型別檢查工具簡介
johnlinvc
0
630
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
270
Other Decks in Programming
See All in Programming
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
300
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
670
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
490
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
480
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
630
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.6k
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
霧の中の代数的エフェクト
funnyycat
1
490
Featured
See All Featured
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
310
Designing for Timeless Needs
cassininazir
1
430
Prompt Engineering for Job Search
mfonobong
0
400
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
240
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Mind Mapping
helmedeiros
PRO
1
300
Building Adaptive Systems
keathley
44
3.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
AI: The stuff that nobody shows you
jnunemaker
PRO
9
890
Build your cross-platform service in a week with App Engine
jlugia
234
19k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
56k
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