SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Measurements & Units
WWDC16. Meetup@Wantedly
2016/06/30
About me
Ken Tominaga
The University of Tokyo
Rekimoto Lab
Swift Lover 😍
Measurements

and

Units? 😳
Nike+ Running
Measurements and Units
Added to the Foundation framework
Newly introduced in iOS 10
Support for specifying Measurements and Units
Measurement
public struct Measurement<UnitType : Unit> : Comparable, Equatable {
public let unit: UnitType
public var value: Double
public init(value: Double, unit: UnitType)
}
Calculations With
Measurements
let distanceTraveled = Measurement(value: 20, unit: UnitLength.kilometers)
// 20.0 km
let distanceToGo = Measurement(value: 1.975, unit: UnitLength.kilometers)
// 1.975 km
let totalDistance = distanceTraveled + distanceToGo // 21.975 km
let tripleDistance = 3 * distanceToGo // 5.925 km
let halfDistance = distanceToGo / 2 // 0.9875 km
Properties of a Unit
Symbol “m"
Dimension “meter is a unit of length"
Equivalence 1 m = 3.28084 ft
Unit
public class Unit : NSObject, NSCopying {
public var symbol: String { get }
public init(symbol: String)
}
Dimension
Categories of units
Expressed with different units
• Length: km, m, ft, mi, etc.
Always has a base unit
let meter = UnitLength.baseUnit()
Can perform conversions
• km ft, m mi
Dimension
public class Dimension : Unit {
@NSCopying public var converter: UnitConverter { get }
public init(symbol: String, converter: UnitConverter)
public class func baseUnit() -> Self
}
Dimension
Instances as units
Singletons for most common units
International System of Units
public class UnitLength : Dimension {
/*
Base unit - meters
*/
@NSCopying public class var kilometers: UnitLength { get }
@NSCopying public class var meters: UnitLength { get }
@NSCopying public class var feet: UnitLength { get }
@NSCopying public class var yards: UnitLength { get }
@NSCopying public class var miles: UnitLength { get }
...
}
Dimension
Implicit Conversion
let distanceTraveled = Measurement(value: 2, unit: UnitLength.kilometers)
// 2.0 km
//let distanceToGo = Measurement(value: 1.975, unit: UnitLength.kilometers)
//let totalDistance = distanceTraveled + distanceToGo
let distanceToGo = Measurement(value: 11.3, unit: UnitLength.feet)
// 11.3 ft
let totalDistance = distanceTraveled + distanceToGo
// 2003.44424 m
Next Step
Custom Unit
let syaku =
UnitLength(symbol: " ", converter: UnitConverterLinear(coefficient: 10/33))
// 1 10/30 m
Conversion
baseUnit unit
UnitConverter
• baseUnitValue(fromValue value:)
• value(fromBaseUnitValue baseUnitValue:)
UnitConverterLinear
• baseUnitValue = coefficient * value + constant
• value = (baseUnitValue - constant)/coefficient
Custom Unit
let syaku =
UnitLength(symbol: " ", converter: UnitConverterLinear(coefficient: 10/33))
// 1 10/33 m
let lengthInShayku = Measurement(value: 10, unit: syaku)
// 10.0
let lengthInYards = lengthInShayku.converted(to: UnitLength.yards)
// 3.31397969193245 yd
let lengthInFeet = Measurement(value: 5.3, unit: UnitLength.feet)
// 5.3 ft
lengthInShayku + lengthInFeet
// 4.64574303030303 m
baseUnitValue = 10/ 33 *
= baseUnitValue / (10/33)
Custom Dimension
class UnitImpression : Dimension {
static let good =
UnitImpression(symbol: "👍 ", converter: UnitConverterLinear(coefficient: 1))
static let great =
UnitImpression(symbol: "👏 ", converter: UnitConverterLinear(coefficient: 10))
static let wonderful =
UnitImpression(symbol: "😘 ", converter: UnitConverterLinear(coefficient: 50))
static let lifeChanging =
UnitImpression(symbol: "😍 ", converter: UnitConverterLinear(coefficient: 2000))
override class func baseUnit() -> UnitImpression {
return good
}
}
// Example - Use of Custom Dimension
struct Presentation {
let speaker : String
let title : String
let movement : Measurement<UnitLength>
let duration : Measurement<UnitDuration>
let impression : Measurement<UnitImpression>
var movementRate: Measurement<UnitSpeed> {
let distanceInMeters = movement.converted(to: .meters)
let durationInSeconds = duration.converted(to: .seconds)
return Measurement(
value: distanceInMeters.value / durationInSeconds.value,
unit: UnitSpeed.metersPerSecond)
}
}
// Example - Use of Custom Dimension
let presentation =
Presentation(
speaker: "ken0nek",
title: "Measurements & Units",
movement: Measurement(value: 60, unit: UnitLength.centimeters),
duration: Measurement(value: 10, unit: UnitDuration.minutes),
impression: Measurement(value: 100, unit: UnitImpression.lifeChanging))
presentation.movementRate // 0.001 m/s
presentation.impression // 100.0 😍
presentation.impression.converted(to: UnitImpression.baseUnit()) // 200000.0 👍
Formatting Is Hard
Country Expected String
Japan “5 km"
United States “3.1 mi”
Egypt “‫كم‬ ٥”
China “5 "
MeasurementFormatter
New formatter
Measurements and Units
Locale-aware formatting
MeasurementFormatter
public class MeasurementFormatter : Formatter {
public var unitOptions: MeasurementFormatter.UnitOptions
public var unitStyle: Formatter.UnitStyle
@NSCopying public var locale: Locale!
@NSCopying public var numberFormatter: NumberFormatter!
public func string(from measurement: Measurement<Unit>) -> String
public func string(from unit: Unit) -> String
}
Unit Options
Formats preferred unit of locale by default
Takes purpose into account
Unit Options
UnitOptions Measurement Locale Example String
.providedUnit
value: 5,
unit: .kilometers
“en_US” “5 km"
.naturalScale
value: 1000,
unit: .meters
“fr_FR” “1 km"
.temperatureWithoutUnit
value: 90,
unit: .fahrenheit
“en_US” “90°"
MeasurementFormatter
// Current Locale -> ja_JP
// This code will not work in Xcode8 beta currently :(
let formatter = MeasurementFormatter()
let distance = Measurement(value: 5, unit: UnitLength.miles)
formatter.string(from: distance)
// 8.04672 km
let syaku = UnitLength(symbol: " ",
converter: UnitConverterLinear(coefficient: 10/33))
let syakuDistance = Measurement(value: 660, unit: syaku)
formatter.string(from: syakuDistance)
// 0.2 km
Wrap Up
Support for handling Measurements and Units
Don’t have to care about localizing and formatting
Measurement
Unit
Dimension MeasurementFormatter
UnitConverter
Thank you
References
Measurements and Units - WWDC 2016 - Videos - Apple
Developer
Measurement - Apple Developer Documentation
Unit - Apple Developer Documentation
Dimension - Apple Developer Documentation
UnitConverterLinear - Apple Developer Documentation
MeasurementFormatter - Apple Developer Documentation
About Internationalization and Localization
Bug Reports
The string() method of the
MeasurementFormatter... | Apple Developer
Forums
Swift Compiler on iOS 10 does not properly find
MeasurementFormatter.string(from:) method

Weitere ähnliche Inhalte

Was ist angesagt?

Standard system for weights
Standard system for weightsStandard system for weights
Standard system for weightsuog
 
Measurement Unit Vocabulary/Word Wall
Measurement Unit Vocabulary/Word WallMeasurement Unit Vocabulary/Word Wall
Measurement Unit Vocabulary/Word WallMsBenesova
 
Dimestion and standards, SI Unit system
Dimestion and standards, SI Unit systemDimestion and standards, SI Unit system
Dimestion and standards, SI Unit systemDr Naim R Kidwai
 
Diploma sem 2 applied science physics-unit 1-chap 1 measurements
Diploma sem 2 applied science physics-unit 1-chap 1 measurementsDiploma sem 2 applied science physics-unit 1-chap 1 measurements
Diploma sem 2 applied science physics-unit 1-chap 1 measurementsRai University
 
MeasurementKCSE
MeasurementKCSEMeasurementKCSE
MeasurementKCSELightkcse
 
Units & measurements
Units &  measurementsUnits &  measurements
Units & measurementsAmol Kumbhar
 
Grade 9 U0-L3 - Measurement
Grade 9 U0-L3 - MeasurementGrade 9 U0-L3 - Measurement
Grade 9 U0-L3 - Measurementgruszecki1
 
1-2 Physics & Measurement
1-2 Physics & Measurement1-2 Physics & Measurement
1-2 Physics & Measurementrkelch
 
Units and measurements - Basic SI units
Units and measurements - Basic SI unitsUnits and measurements - Basic SI units
Units and measurements - Basic SI unitsBhagavathyP
 
Unit1: Physical Quantities & Units
Unit1: Physical Quantities & UnitsUnit1: Physical Quantities & Units
Unit1: Physical Quantities & UnitsHira Rizvi
 
Unit physics slides by varsha parakh
Unit  physics   slides by varsha parakhUnit  physics   slides by varsha parakh
Unit physics slides by varsha parakhvarsha parakh
 
Introductory Physics - Physical Quantities, Units and Measurement
Introductory Physics - Physical Quantities, Units and MeasurementIntroductory Physics - Physical Quantities, Units and Measurement
Introductory Physics - Physical Quantities, Units and MeasurementSutharsan Isles
 
Physical quantities, units & measurements complete
Physical quantities, units & measurements completePhysical quantities, units & measurements complete
Physical quantities, units & measurements completeMak Dawoodi
 

Was ist angesagt? (19)

Standard system for weights
Standard system for weightsStandard system for weights
Standard system for weights
 
Measurement Unit Vocabulary/Word Wall
Measurement Unit Vocabulary/Word WallMeasurement Unit Vocabulary/Word Wall
Measurement Unit Vocabulary/Word Wall
 
01 physical quantities
01 physical quantities01 physical quantities
01 physical quantities
 
Dimestion and standards, SI Unit system
Dimestion and standards, SI Unit systemDimestion and standards, SI Unit system
Dimestion and standards, SI Unit system
 
Basic Physics Quantities
Basic Physics QuantitiesBasic Physics Quantities
Basic Physics Quantities
 
01 unit and measurement
01 unit and measurement01 unit and measurement
01 unit and measurement
 
Diploma sem 2 applied science physics-unit 1-chap 1 measurements
Diploma sem 2 applied science physics-unit 1-chap 1 measurementsDiploma sem 2 applied science physics-unit 1-chap 1 measurements
Diploma sem 2 applied science physics-unit 1-chap 1 measurements
 
MeasurementKCSE
MeasurementKCSEMeasurementKCSE
MeasurementKCSE
 
Units & measurements
Units &  measurementsUnits &  measurements
Units & measurements
 
Grade 9 U0-L3 - Measurement
Grade 9 U0-L3 - MeasurementGrade 9 U0-L3 - Measurement
Grade 9 U0-L3 - Measurement
 
1-2 Physics & Measurement
1-2 Physics & Measurement1-2 Physics & Measurement
1-2 Physics & Measurement
 
Units and measurements - Basic SI units
Units and measurements - Basic SI unitsUnits and measurements - Basic SI units
Units and measurements - Basic SI units
 
Unit1: Physical Quantities & Units
Unit1: Physical Quantities & UnitsUnit1: Physical Quantities & Units
Unit1: Physical Quantities & Units
 
Unit physics slides by varsha parakh
Unit  physics   slides by varsha parakhUnit  physics   slides by varsha parakh
Unit physics slides by varsha parakh
 
Introductory Physics - Physical Quantities, Units and Measurement
Introductory Physics - Physical Quantities, Units and MeasurementIntroductory Physics - Physical Quantities, Units and Measurement
Introductory Physics - Physical Quantities, Units and Measurement
 
Physical quantities, units & measurements complete
Physical quantities, units & measurements completePhysical quantities, units & measurements complete
Physical quantities, units & measurements complete
 
Unit Conversion in surveying
Unit Conversion in surveying Unit Conversion in surveying
Unit Conversion in surveying
 
Scientific units
Scientific unitsScientific units
Scientific units
 
S01-L03-SI Units
S01-L03-SI UnitsS01-L03-SI Units
S01-L03-SI Units
 

Andere mochten auch

What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...将之 小野
 
1 Units, Measurements, & Conversions
1 Units, Measurements, & Conversions1 Units, Measurements, & Conversions
1 Units, Measurements, & ConversionsJoseph Cadray
 
Preparation and approaches of cost estimates
Preparation and approaches of cost estimatesPreparation and approaches of cost estimates
Preparation and approaches of cost estimatesnagashree123
 
unit 207 carry out first fix flooring and roofing
unit 207 carry out first fix flooring and roofingunit 207 carry out first fix flooring and roofing
unit 207 carry out first fix flooring and roofingkevin porter
 
Elasticsearch for Hackadoll
Elasticsearch for HackadollElasticsearch for Hackadoll
Elasticsearch for Hackadollmosa siru
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSDerek Lee Boire
 
Bamboo as a buil ding material
Bamboo as a buil ding materialBamboo as a buil ding material
Bamboo as a buil ding materialJayesh Sreedhar
 
Writing Clean Code in Swift
Writing Clean Code in SwiftWriting Clean Code in Swift
Writing Clean Code in SwiftDerek Lee Boire
 
Go, memcached, microservices
Go, memcached, microservicesGo, memcached, microservices
Go, memcached, microservicesmosa siru
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンドYUKI Kaoru
 
Project Specifications
Project SpecificationsProject Specifications
Project SpecificationsEric Anderson
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフローadd20
 
Overhead analysis
Overhead analysisOverhead analysis
Overhead analysisgk44
 
ニュースパスのクローラーアーキテクチャとマイクロサービス
ニュースパスのクローラーアーキテクチャとマイクロサービスニュースパスのクローラーアーキテクチャとマイクロサービス
ニュースパスのクローラーアーキテクチャとマイクロサービスmosa siru
 
Green Building Materials &amp; Techniques3 Nov 2009spm
Green Building Materials &amp; Techniques3 Nov 2009spmGreen Building Materials &amp; Techniques3 Nov 2009spm
Green Building Materials &amp; Techniques3 Nov 2009spmDR.S.P. MISHRA
 

Andere mochten auch (20)

What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
 
1 Units, Measurements, & Conversions
1 Units, Measurements, & Conversions1 Units, Measurements, & Conversions
1 Units, Measurements, & Conversions
 
Preparation and approaches of cost estimates
Preparation and approaches of cost estimatesPreparation and approaches of cost estimates
Preparation and approaches of cost estimates
 
unit 207 carry out first fix flooring and roofing
unit 207 carry out first fix flooring and roofingunit 207 carry out first fix flooring and roofing
unit 207 carry out first fix flooring and roofing
 
Elasticsearch for Hackadoll
Elasticsearch for HackadollElasticsearch for Hackadoll
Elasticsearch for Hackadoll
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOS
 
iOSのFileProtection
iOSのFileProtectioniOSのFileProtection
iOSのFileProtection
 
Standard Costing
Standard CostingStandard Costing
Standard Costing
 
Bamboo as a buil ding material
Bamboo as a buil ding materialBamboo as a buil ding material
Bamboo as a buil ding material
 
Writing Clean Code in Swift
Writing Clean Code in SwiftWriting Clean Code in Swift
Writing Clean Code in Swift
 
Converting unit measures
Converting unit measuresConverting unit measures
Converting unit measures
 
Go, memcached, microservices
Go, memcached, microservicesGo, memcached, microservices
Go, memcached, microservices
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンド
 
Project Specifications
Project SpecificationsProject Specifications
Project Specifications
 
Units of measurement
Units of measurementUnits of measurement
Units of measurement
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフロー
 
Earthwork
EarthworkEarthwork
Earthwork
 
Overhead analysis
Overhead analysisOverhead analysis
Overhead analysis
 
ニュースパスのクローラーアーキテクチャとマイクロサービス
ニュースパスのクローラーアーキテクチャとマイクロサービスニュースパスのクローラーアーキテクチャとマイクロサービス
ニュースパスのクローラーアーキテクチャとマイクロサービス
 
Green Building Materials &amp; Techniques3 Nov 2009spm
Green Building Materials &amp; Techniques3 Nov 2009spmGreen Building Materials &amp; Techniques3 Nov 2009spm
Green Building Materials &amp; Techniques3 Nov 2009spm
 

Ähnlich wie Measurements and Units in iOS 10

F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordKit Eason
 
Adding Uncertainty and Units to Quantity Types in Software Models
Adding Uncertainty and Units to Quantity Types in Software ModelsAdding Uncertainty and Units to Quantity Types in Software Models
Adding Uncertainty and Units to Quantity Types in Software ModelsTanja Mayerhofer
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)Giuseppe Filograno
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 seriesopenbala
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of SignalsCoding Academy
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in pythonAshmita Dhakal
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxfaithxdunce63732
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in PracticeOutware Mobile
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxvishal choudhary
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into SwiftSarath C
 
Applications of Derivatives
Applications of DerivativesApplications of Derivatives
Applications of DerivativesAmshalEjaz1
 
get your units right
get your units rightget your units right
get your units rightFelixSchultze
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxAASTHA76
 

Ähnlich wie Measurements and Units in iOS 10 (20)

F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
 
Adding Uncertainty and Units to Quantity Types in Software Models
Adding Uncertainty and Units to Quantity Types in Software ModelsAdding Uncertainty and Units to Quantity Types in Software Models
Adding Uncertainty and Units to Quantity Types in Software Models
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
LBM 1
LBM 1LBM 1
LBM 1
 
Function C++
Function C++ Function C++
Function C++
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
3. Polymorphism.pptx
3. Polymorphism.pptx3. Polymorphism.pptx
3. Polymorphism.pptx
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
 
Applications of Derivatives
Applications of DerivativesApplications of Derivatives
Applications of Derivatives
 
get your units right
get your units rightget your units right
get your units right
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Measurements and Units in iOS 10

  • 1. Measurements & Units WWDC16. Meetup@Wantedly 2016/06/30
  • 2. About me Ken Tominaga The University of Tokyo Rekimoto Lab Swift Lover 😍
  • 5. Measurements and Units Added to the Foundation framework Newly introduced in iOS 10 Support for specifying Measurements and Units
  • 6. Measurement public struct Measurement<UnitType : Unit> : Comparable, Equatable { public let unit: UnitType public var value: Double public init(value: Double, unit: UnitType) }
  • 7. Calculations With Measurements let distanceTraveled = Measurement(value: 20, unit: UnitLength.kilometers) // 20.0 km let distanceToGo = Measurement(value: 1.975, unit: UnitLength.kilometers) // 1.975 km let totalDistance = distanceTraveled + distanceToGo // 21.975 km let tripleDistance = 3 * distanceToGo // 5.925 km let halfDistance = distanceToGo / 2 // 0.9875 km
  • 8. Properties of a Unit Symbol “m" Dimension “meter is a unit of length" Equivalence 1 m = 3.28084 ft
  • 9. Unit public class Unit : NSObject, NSCopying { public var symbol: String { get } public init(symbol: String) }
  • 10. Dimension Categories of units Expressed with different units • Length: km, m, ft, mi, etc. Always has a base unit let meter = UnitLength.baseUnit() Can perform conversions • km ft, m mi
  • 11. Dimension public class Dimension : Unit { @NSCopying public var converter: UnitConverter { get } public init(symbol: String, converter: UnitConverter) public class func baseUnit() -> Self }
  • 12. Dimension Instances as units Singletons for most common units International System of Units public class UnitLength : Dimension { /* Base unit - meters */ @NSCopying public class var kilometers: UnitLength { get } @NSCopying public class var meters: UnitLength { get } @NSCopying public class var feet: UnitLength { get } @NSCopying public class var yards: UnitLength { get } @NSCopying public class var miles: UnitLength { get } ... }
  • 14. Implicit Conversion let distanceTraveled = Measurement(value: 2, unit: UnitLength.kilometers) // 2.0 km //let distanceToGo = Measurement(value: 1.975, unit: UnitLength.kilometers) //let totalDistance = distanceTraveled + distanceToGo let distanceToGo = Measurement(value: 11.3, unit: UnitLength.feet) // 11.3 ft let totalDistance = distanceTraveled + distanceToGo // 2003.44424 m
  • 16. Custom Unit let syaku = UnitLength(symbol: " ", converter: UnitConverterLinear(coefficient: 10/33)) // 1 10/30 m
  • 17. Conversion baseUnit unit UnitConverter • baseUnitValue(fromValue value:) • value(fromBaseUnitValue baseUnitValue:) UnitConverterLinear • baseUnitValue = coefficient * value + constant • value = (baseUnitValue - constant)/coefficient
  • 18. Custom Unit let syaku = UnitLength(symbol: " ", converter: UnitConverterLinear(coefficient: 10/33)) // 1 10/33 m let lengthInShayku = Measurement(value: 10, unit: syaku) // 10.0 let lengthInYards = lengthInShayku.converted(to: UnitLength.yards) // 3.31397969193245 yd let lengthInFeet = Measurement(value: 5.3, unit: UnitLength.feet) // 5.3 ft lengthInShayku + lengthInFeet // 4.64574303030303 m baseUnitValue = 10/ 33 * = baseUnitValue / (10/33)
  • 19. Custom Dimension class UnitImpression : Dimension { static let good = UnitImpression(symbol: "👍 ", converter: UnitConverterLinear(coefficient: 1)) static let great = UnitImpression(symbol: "👏 ", converter: UnitConverterLinear(coefficient: 10)) static let wonderful = UnitImpression(symbol: "😘 ", converter: UnitConverterLinear(coefficient: 50)) static let lifeChanging = UnitImpression(symbol: "😍 ", converter: UnitConverterLinear(coefficient: 2000)) override class func baseUnit() -> UnitImpression { return good } }
  • 20. // Example - Use of Custom Dimension struct Presentation { let speaker : String let title : String let movement : Measurement<UnitLength> let duration : Measurement<UnitDuration> let impression : Measurement<UnitImpression> var movementRate: Measurement<UnitSpeed> { let distanceInMeters = movement.converted(to: .meters) let durationInSeconds = duration.converted(to: .seconds) return Measurement( value: distanceInMeters.value / durationInSeconds.value, unit: UnitSpeed.metersPerSecond) } }
  • 21. // Example - Use of Custom Dimension let presentation = Presentation( speaker: "ken0nek", title: "Measurements & Units", movement: Measurement(value: 60, unit: UnitLength.centimeters), duration: Measurement(value: 10, unit: UnitDuration.minutes), impression: Measurement(value: 100, unit: UnitImpression.lifeChanging)) presentation.movementRate // 0.001 m/s presentation.impression // 100.0 😍 presentation.impression.converted(to: UnitImpression.baseUnit()) // 200000.0 👍
  • 22. Formatting Is Hard Country Expected String Japan “5 km" United States “3.1 mi” Egypt “‫كم‬ ٥” China “5 "
  • 24. MeasurementFormatter public class MeasurementFormatter : Formatter { public var unitOptions: MeasurementFormatter.UnitOptions public var unitStyle: Formatter.UnitStyle @NSCopying public var locale: Locale! @NSCopying public var numberFormatter: NumberFormatter! public func string(from measurement: Measurement<Unit>) -> String public func string(from unit: Unit) -> String }
  • 25. Unit Options Formats preferred unit of locale by default Takes purpose into account
  • 26. Unit Options UnitOptions Measurement Locale Example String .providedUnit value: 5, unit: .kilometers “en_US” “5 km" .naturalScale value: 1000, unit: .meters “fr_FR” “1 km" .temperatureWithoutUnit value: 90, unit: .fahrenheit “en_US” “90°"
  • 27. MeasurementFormatter // Current Locale -> ja_JP // This code will not work in Xcode8 beta currently :( let formatter = MeasurementFormatter() let distance = Measurement(value: 5, unit: UnitLength.miles) formatter.string(from: distance) // 8.04672 km let syaku = UnitLength(symbol: " ", converter: UnitConverterLinear(coefficient: 10/33)) let syakuDistance = Measurement(value: 660, unit: syaku) formatter.string(from: syakuDistance) // 0.2 km
  • 28. Wrap Up Support for handling Measurements and Units Don’t have to care about localizing and formatting Measurement Unit Dimension MeasurementFormatter UnitConverter
  • 30. References Measurements and Units - WWDC 2016 - Videos - Apple Developer Measurement - Apple Developer Documentation Unit - Apple Developer Documentation Dimension - Apple Developer Documentation UnitConverterLinear - Apple Developer Documentation MeasurementFormatter - Apple Developer Documentation About Internationalization and Localization
  • 31. Bug Reports The string() method of the MeasurementFormatter... | Apple Developer Forums Swift Compiler on iOS 10 does not properly find MeasurementFormatter.string(from:) method