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
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
Go の GC の不得意な部分を克服したい
taiyow
3
790
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
たのしいparse.y
ydah
3
120
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Beyond ORM
77web
6
740
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
770
Security_for_introducing_eBPF
kentatada
0
110
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Site-Speed That Sticks
csswizardry
2
190
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Embracing the Ebb and Flow
colly
84
4.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Building Applications with DynamoDB
mza
91
6.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.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