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
C++でシェーダを書く
fadis
6
4.1k
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
Jakarta EE meets AI
ivargrimstad
0
610
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
イベント駆動で成長して委員会
happymana
1
320
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
YesSQL, Process and Tooling at Scale
rocio
169
14k
GraphQLとの向き合い方2022年版
quramy
43
13k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Ruby is Unlike a Banana
tanoku
97
11k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Embracing the Ebb and Flow
colly
84
4.5k
Automating Front-end Workflow
addyosmani
1366
200k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
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