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
Measurement And Unitを試した話
Search
Atsushi Uchida (utwang)
July 31, 2016
Programming
0
560
Measurement And Unitを試した話
集まれSwift好き!Swift愛好会 vol9での発表資料です。
Atsushi Uchida (utwang)
July 31, 2016
Tweet
Share
More Decks by Atsushi Uchida (utwang)
See All by Atsushi Uchida (utwang)
Apple公式ガイドを さっくりと読んでまとめてみた UIScrollView編
utwang
0
220
Apple公式ガイドさっくりまとめ ファイルシステム編
utwang
0
37
頻出pryコマンド
utwang
0
120
設計ポイントの 比較で知る Backbone.js
utwang
9
7k
Other Decks in Programming
See All in Programming
快速入門可觀測性
blueswen
0
380
情報漏洩させないための設計
kubotak
3
330
Exploring: Partial and Independent Composables
blackbracken
0
100
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
510
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
命名をリントする
chiroruxx
1
420
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
780
선언형 UI에서의 상태관리
l2hyunwoo
0
180
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
270
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
testcontainers のススメ
sgash708
1
120
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Documentation Writing (for coders)
carmenintech
66
4.5k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Being A Developer After 40
akosma
87
590k
The Cult of Friendly URLs
andyhume
78
6.1k
BBQ
matthewcrist
85
9.4k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Transcript
Measurement And Unit Λࢼͨ͠ 2016/7/31 ू·ΕSwift͖ʂSwiftѪձ vol9
ࣗݾհ ాರ೭ (@utwang) • ϑϦʔϥϯεΤϯδχΞ כϲ࡚ࡏॅ • Swift, Rails, Javascript
• εϊʔϘʔυ͖ • ݸਓͰυϥΠϒͷׂΓצΞϓϦͩ͠·ͨ͠
׆ಈ ԣपลͰษڧձ/ΠϕϯτΛͬͯ·͢ • Railsͷ͘͘ձ/Swiftͷ͘͘ձ
• 8/21() Ϋϩʔϥʔͷӡ༻ʹ·ͭΘΔLTΠϕϯτ εϐʔΧʔɺઈࢍืूதͰ͢
ΞδΣϯμ • Ϟνϕʔγϣϯ • Measurementͱ • Կ͕Ͱ͖Δ͔ʁ • Measurement/Unitͷ͍ํ •
MeasurementΛߏ͢ΔΫϥε • ͬͯΈͯͷײ
Xcode8 beta3Ͱࢼͨ͠༰Ͱ͢ɻ ਖ਼ࣜϦϦʔε൛Ͱ༰͕ҟͳΔՄೳੑ͕͋Γ·͢ɻ
Ϟνϕʔγϣϯ • ݸਓͰ࡞ͬͨΞϓϦͷӳޠରԠ • ݴޠಉ͡Ͱ୯Ґ͕ҟͳΔ߹͕͋ Δ͕ɺશ෦ϩʔΧϥΠζରԠ͢Δͷ େม • ΞϝϦΧ: ӳޠ
/mile /gallon(US) /$ • ΠΪϦε: ӳޠ /mile /gallon(UK) /£ • Χφμɹ: ӳޠ /km /liter /CA$ • WWDC2016Ͱൃද͞Ε ͨ"Measurement And Unit"ΛௐΔ
Measurementͱ • iOS10͔Βར༻Ͱ͖ΔFoundationͷίϯϙʔωϯτ • Swift2.3ͰNSMeasurement • Swift3.0ͰMeasurement • ܭྔͷ֓೦Λදݱͨ͠ΫϥεͰྔͱ୯ҐΛऔΓѻ͏
Կ͕Ͱ͖Δ͔ʁ • ͋Δܭྔͷ୯ҐΛผͷ୯ҐมͰ͖Δ • 15 km <-> 9.32 mile •
30 kg <-> 13.6 lb (ϙϯυ) • localeʹ߹Θͤͯదͳ୯ҐΛϑΥʔϚοτ • ΧελϜͷ୯ҐɺܭྔΛ࡞
Measurementͷ͍ํ(1) ྔͱ୯ҐΛ1ͭͷΠϯελϯεͱͯ͠ཧɾίϯόʔτ • ج४ͱͳΔ୯Ґ(baseUnit)Λݩʹม • ͞ͷ߹meter͕baseUnitͱͳΔ let distanceInJapan = Measurement(value:
80, unit: UnitLength.kilometers) // => 80.0 km let distanceInUS = distanceInJapan.converted(to: UnitLength.miles) // => 49.7098189319845 mi
Measurementͷ͍ํ(2) ΧελϜͷ୯ҐΛ࡞Ͱ͖Δ • ೩අͷϓϦηοτ L/100km, mile/gal(US), mile/gal(UK) • ຊͰkm/LͰද͢ͷ͕Ұൠతɻج४ͷL/100km͔ΒͷൺΛ ࢦఆͯ͠৽ͨʹ୯ҐΛ࡞Δɻ
let kmPerLiter = UnitFuelEfficiency(symbol: "km/l", converter: UnitConverterLinear(coefficient: 0.25)) //UnitFuelEfficiencyͷextensionͱͯ͠ఆٛՄೳ let fuelEfficiencyInJp = Measurement(value: 10, unit: kmPerLiter) // => 10 km/L
Measurementͷ͍ํ(3) localeʹ߹Θͤͨ୯ҐΛมߋ • LocaleใΛͭMeasurementFormatter͕༻ҙ͞Ε͍ͯΔ • Regionʹదͨ͠୯ҐΛදࣔ͢Δ let mFormatter = MeasurementFormatter()
mFormatter.unitStyle = .short let distance = Measurement(value: 400, unit: UnitLength.kilometers) mFormatter.string(from: distance) // => 248.549 mi (in US) // => 400 km (in Canada)
MeasurementΛߏ͢ ΔΫϥε • Measurement(ܭྔ) • Unit(୯Ґ) • Dimension(ཧྔͷ࣍ݩ) • நΫϥε
• UnitXXX (UnitAngle, UnitLength, UnitVolume ...) • Dimensionͷ۩Ϋϥε • UnitConverter
MeasurementΛߏ͢ ΔΫϥε ৽͍͠ཧྔͷ࣍ݩΛ࡞Δ߹ • DimensionΛܧঝͨ͠UnitTypingSpeed Λ࡞ • ֤୯Ґͱͯ͠UnitTypingSpeedܕΛࣗ Λฦ͢ϓϩύςΟΛ༻ҙ͢Δ class
UnitTypingSpeed: Dimension { static let punchPerSecond = UnitTypingSpeed(symbol: "punch/s") static let charsPerMinute = UnitTypingSpeed(symbol: "chars/min", converter: UnitPunchToCharConverter())
ͬͯΈͯͷײ ͍ॴ • ͋Δ୯ҐͷܭྔΛผͷ୯ҐͰද͍ࣔͨ͠߹ • ҬͰ୯ҐΛΓସ͍͑ͨ߹ Θͳ͍͍ͯ͘(͑ͳ͍)ॴ • ୯ҐΛ୯ͳΔϥϕϧͱͯ͠ද͍ࣔͨ͠߹ •
֎෦ཁૉͰൺ͕มΘΔͳͲɺ୯७ͳมͰͳ͍߹ (୯ՁͳͲҝସมಈͷӨڹΛड͚Δ(20 $/lb => 2500 ¥/kg))
͍ॴ
͓·͚ ୯Ґͷॻ͖ํࠃࡍతʹܾΊΒΕ͓ͯΓɺͷޙʹ֯̍Ϛε ۭ͚ɺ୯ҐΛॻ͘ɻྫ͑ɺ1.50 kgͱॻ͘ɻ — ग़యݩ: Wikipedia