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
550
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
35
頻出pryコマンド
utwang
0
120
設計ポイントの 比較で知る Backbone.js
utwang
9
6.9k
Other Decks in Programming
See All in Programming
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
CSC509 Lecture 12
javiergs
PRO
0
160
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Jakarta EE meets AI
ivargrimstad
0
160
Better Code Design in PHP
afilina
PRO
0
130
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
It's Worth the Effort
3n
183
27k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
What's new in Ruby 2.0
geeforr
343
31k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Facilitating Awesome Meetings
lara
50
6.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
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