苹果的解释是 Base unit - metersPerSecondSquared ,也就是 秒每平方米的意思(㎡/s),学过中学物理都知道这个事加速度的意思,NSUnitAcceleration提供了两个属性
@property (class, readonly, copy) NSUnitAcceleration *metersPerSecondSquared;
@property (class, readonly, copy) NSUnitAcceleration *gravity;
从字面意思来看第一个是 秒每平方米 , 第二个是重力加速度;那么这东西干啥子用的了 ? 我们打开Apple的API不难发现
很多人就懵逼了这他妈是个神马鬼来段代码,上篇博客上我提到 NSMeasurementFormatter 这个鬼
NSMeasurementFormatter *formatter = [[NSMeasurementFormatter alloc] init];
[formatter setUnitOptions:NSMeasurementFormatterUnitOptionsProvidedUnit];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
NSMeasurement *measurement1 = [[NSMeasurement alloc] initWithDoubleValue:12 unit:NSUnitAcceleration.metersPerSecondSquared];
NSMeasurement *measurement2 = [[NSMeasurement alloc] initWithDoubleValue:12 unit:NSUnitAcceleration.gravity];
NSLog(@"%@",[formatter stringFromMeasurement:measurement1]); // 12米/秒²
NSLog(@"%@",[formatter stringFromMeasurement:measurement2]); // 12 G
这个鬼的作用是,把指定数字封装成 加速度的,然后按照一定的格式输出,好吧!新技能get下
Base unit - degrees , degrees 其实是度的意思,eg:这个三角形的角多少度
Apple提供了若干弧度单位如下
@property (class, readonly, copy) NSUnitAngle *degrees;//度(°)
@property (class, readonly, copy) NSUnitAngle *arcMinutes;//分(ʹ)
@property (class, readonly, copy) NSUnitAngle *arcSeconds;//秒(ʺ)
@property (class, readonly, copy) NSUnitAngle *radians;//弧度(rad)
@property (class, readonly, copy) NSUnitAngle *gradians;//百分度制(grad),1G = 直角的1%
@property (class, readonly, copy) NSUnitAngle *revolutions;//转(rev)
我们来看个代码,说多了都是废话,我们将90度转成对应的其他单位
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:90 unit:NSUnitAngle.degrees];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitAngle.arcMinutes];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitAngle.arcSeconds];
NSMeasurement *measurement3 = [measurement measurementByConvertingToUnit:NSUnitAngle.radians];
NSMeasurement *measurement4 = [measurement measurementByConvertingToUnit:NSUnitAngle.gradians];
NSMeasurement *measurement5 = [measurement measurementByConvertingToUnit:NSUnitAngle.revolutions];
NSLog(@"%f",measurement1.doubleValue); // 5399.892002
NSLog(@"%f",measurement2.doubleValue); // 323997.408021
NSLog(@"%f",measurement3.doubleValue); // 1.570796
NSLog(@"%f",measurement4.doubleValue); // 100.000000
NSLog(@"%f",measurement5.doubleValue); // 0.250000
其实我们不难看出这个NSMeasurement的使用方法,即先初始化一个数值对应单位,然后在通过这个单位转成另外一个单位并获取值,为神马90度转分秒之后不是整数了?我觉得这种问题我在这里就不用解释了 90° == π/2 rad , 90° == 100grad , 90° == 0.25rev ,ok 角度单位就介绍到这里
Base unit - squareMeters ,基础单位平方米
@property (class, readonly, copy) NSUnitArea *squareMegameters;//平方表 Megameter兆米(=100万米)
@property (class, readonly, copy) NSUnitArea *squareKilometers;//平方千米
@property (class, readonly, copy) NSUnitArea *squareMeters;//平方米
@property (class, readonly, copy) NSUnitArea *squareCentimeters;///平方厘米
@property (class, readonly, copy) NSUnitArea *squareMillimeters;///平方毫米
@property (class, readonly, copy) NSUnitArea *squareMicrometers;///平方微米
@property (class, readonly, copy) NSUnitArea *squareNanometers;///平方纳米
@property (class, readonly, copy) NSUnitArea *squareInches;///平方英寸
@property (class, readonly, copy) NSUnitArea *squareFeet;///平方英尺
@property (class, readonly, copy) NSUnitArea *squareYards;///平方码
@property (class, readonly, copy) NSUnitArea *squareMiles;///平方英里
@property (class, readonly, copy) NSUnitArea *acres;///英亩
@property (class, readonly, copy) NSUnitArea *ares;///公亩(等于100平方米)
@property (class, readonly, copy) NSUnitArea *hectares;///公顷
同样需要来一段代码验证码
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:100000 unit:NSUnitArea.squareMeters];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitArea.squareKilometers];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitArea.squareCentimeters];
NSMeasurement *measurement3 = [measurement measurementByConvertingToUnit:NSUnitArea.squareFeet];
NSMeasurement *measurement4 = [measurement measurementByConvertingToUnit:NSUnitArea.ares];
NSMeasurement *measurement5 = [measurement measurementByConvertingToUnit:NSUnitArea.hectares];
NSLog(@"%f",measurement1.doubleValue); // 0.100000
NSLog(@"%f",measurement2.doubleValue); // 1000000000.000000
NSLog(@"%f",measurement3.doubleValue); // 1076391.505118
NSLog(@"%f",measurement4.doubleValue); // 1000.000000
NSLog(@"%f",measurement5.doubleValue); // 10.000000
Base unit - gramsPerLiter ,这个名字的确略显抽象,其实用我们物理的话来说就是 密度 ,简直就是坑爹,来张图
首先看下这个货给我们提供了神马
@property (class, readonly, copy) NSUnitConcentrationMass *gramsPerLiter; //克每升
@property (class, readonly, copy) NSUnitConcentrationMass *milligramsPerDeciliter;//毫克每分升
+ (NSUnitConcentrationMass *)millimolesPerLiterWithGramsPerMole:(double)gramsPerMole; // 毫摩尔每升克每摩尔
如何使用了。。。 必须来段代码。。
NSMeasurement *measurement1 = [[NSMeasurement alloc] initWithDoubleValue:7890 unit:NSUnitConcentrationMass.gramsPerLiter];
NSMeasurement *measurement2 = [measurement1 measurementByConvertingToUnit:NSUnitConcentrationMass.milligramsPerDeciliter];
NSLog(@"%f",measurement1.doubleValue); // 7890.000000
NSLog(@"%f",measurement2.doubleValue); // 789000.000000
这个是两个单位之间的转换,那么这个货不老实,提供了一个类方法
来段代码
NSMeasurement *measurement1 = [[NSMeasurement alloc] initWithDoubleValue:100 unit:NSUnitConcentrationMass.gramsPerLiter];
NSMeasurement *measurement2 = [[NSMeasurement alloc] initWithDoubleValue:1000000 unit:NSUnitConcentrationMass.milligramsPerDeciliter];
NSMeasurement *measurement3 = [[NSMeasurement alloc] initWithDoubleValue:1 unit:[NSUnitConcentrationMass millimolesPerLiterWithGramsPerMole:1]];
NSMeasurementFormatter *formatter = [[NSMeasurementFormatter alloc] init];
[formatter setUnitOptions:NSMeasurementFormatterUnitOptionsProvidedUnit];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
NSLog(@"%@",[formatter stringFromMeasurement:measurement1]); // 100 g/L
NSLog(@"%@",[formatter stringFromMeasurement:measurement2]); // 10,000 g/L
NSLog(@"%@",[formatter stringFromMeasurement:measurement3]); // 18 g/L
Base unit - partsPerMillion ,百万分之几
@property (class, readonly, copy) NSUnitDispersion *partsPerMillion;//百万分之几
这个真是良心就一个属性,来段代码
NSMeasurement *measurement1 = [[NSMeasurement alloc] initWithDoubleValue:90 unit:NSUnitDispersion.partsPerMillion];
NSMeasurementFormatter *formatter = [[NSMeasurementFormatter alloc] init];
[formatter setUnitOptions:NSMeasurementFormatterUnitOptionsProvidedUnit];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
NSLog(@"%@",[formatter stringFromMeasurement:measurement1]); // 90 ppm
Base unit - seconds 基础单位是秒
@property (class, readonly, copy) NSUnitDuration *seconds;//秒
@property (class, readonly, copy) NSUnitDuration *minutes;//分
@property (class, readonly, copy) NSUnitDuration *hours;//小时
这个应该是用的最多的一个转换工具了,因为时间运算我们经常会用到的,时分秒之间的相互转换
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:1500 unit:NSUnitDuration.seconds];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitDuration.minutes];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitDuration.hours];
NSLog(@"%f",measurement1.doubleValue); // 25.000000
NSLog(@"%f",measurement2.doubleValue); // 0.416667
Base unit - coulombs 基础单位是库仑,先来看下提供的单位 ,然后来一个公式 1库仑=1安培·1秒
@property (class, readonly, copy) NSUnitElectricCharge *coulombs;//库仑
@property (class, readonly, copy) NSUnitElectricCharge *megaampereHours;//兆安小时
@property (class, readonly, copy) NSUnitElectricCharge *kiloampereHours;//安培小时
@property (class, readonly, copy) NSUnitElectricCharge *ampereHours;//安培小时
@property (class, readonly, copy) NSUnitElectricCharge *milliampereHours;//毫安小时
@property (class, readonly, copy) NSUnitElectricCharge *microampereHours;//微安小时
这个跟上面的基本类似,但是还是来段代码
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:8000000000 unit:NSUnitElectricCharge.coulombs];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitElectricCharge.coulombs];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitElectricCharge.megaampereHours];
NSLog(@"%f",measurement1.doubleValue); // 8000000000.000000
NSLog(@"%f",measurement2.doubleValue); // 2.222222
其他的我就不解释了
Base unit - amperes 基本单位安培
@property (class, readonly, copy) NSUnitElectricCurrent *megaamperes;//兆安
@property (class, readonly, copy) NSUnitElectricCurrent *kiloamperes;//千安
@property (class, readonly, copy) NSUnitElectricCurrent *amperes;//安
@property (class, readonly, copy) NSUnitElectricCurrent *milliamperes;//毫安
@property (class, readonly, copy) NSUnitElectricCurrent *microamperes;//微安
这里来个公式吧
1 MA = 1000KA //方圆十里人畜毙命
1 KA = 1000A
1 A = 1000 mA
1mA = 1000 μA
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:12 unit:NSUnitElectricCurrent.amperes];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitElectricCurrent.kiloamperes];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitElectricCurrent.milliamperes];
NSLog(@"%f",measurement1.doubleValue); // 0.012000
NSLog(@"%f",measurement2.doubleValue); // 12000.000000
电流,当然还有电压电阻了 。。他们是一起的
Base unit - volts ,伏特(我擦,不是福特汽车啊 ,注意)电势差怕你听不懂,电压你就知道了,很明显哥们我学理科的,不然毕业这么久了,这些东西怎么还记得了?
@property (class, readonly, copy) NSUnitElectricPotentialDifference *megavolts;//兆伏
@property (class, readonly, copy) NSUnitElectricPotentialDifference *kilovolts;//千伏
@property (class, readonly, copy) NSUnitElectricPotentialDifference *volts;//伏
@property (class, readonly, copy) NSUnitElectricPotentialDifference *millivolts;//毫伏
@property (class, readonly, copy) NSUnitElectricPotentialDifference *microvolts;//微伏
公式还是需要的
1kV=1000V //人畜毙命
1V=1000mV
1mV=1000μv
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:12 unit:NSUnitElectricPotentialDifference.volts];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitElectricPotentialDifference.kilovolts];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitElectricPotentialDifference.millivolts];
NSLog(@"%f",measurement1.doubleValue); // 0.012000
NSLog(@"%f",measurement2.doubleValue); // 12000.000000
伏特和安培都凑齐了,怎么少得了欧姆了 ?欧姆表示不服
Base unit - ohms , 欧姆来也,简称欧(我擦,跟欧洲的欧一个欧)先复习下高中的公式 , 欧姆的定义是一段电路的两端电压为1V,通过的电流为1A时,这段电路的电阻为1Ω
我擦,扯犊子了 。。 正题
@property (class, readonly, copy) NSUnitElectricResistance *megaohms;//兆欧
@property (class, readonly, copy) NSUnitElectricResistance *kiloohms;//千欧
@property (class, readonly, copy) NSUnitElectricResistance *ohms;//欧
@property (class, readonly, copy) NSUnitElectricResistance *milliohms;//毫欧
@property (class, readonly, copy) NSUnitElectricResistance *microohms;//微欧
代码上
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:12 unit:NSUnitElectricResistance.ohms];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitElectricResistance.kiloohms];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitElectricResistance.milliohms];
NSLog(@"%f",measurement1.doubleValue); // 0.012000
NSLog(@"%f",measurement2.doubleValue); // 12000.000000
公式等其他东西这里不讨论了
Base unit - joules 基础单位 焦耳 , 焦耳定律你知道不?
先看参数
@property (class, readonly, copy) NSUnitEnergy *kilojoules;//千焦耳
@property (class, readonly, copy) NSUnitEnergy *joules;//焦耳
@property (class, readonly, copy) NSUnitEnergy *kilocalories;//千卡
@property (class, readonly, copy) NSUnitEnergy *calories;//卡路里
@property (class, readonly, copy) NSUnitEnergy *kilowattHours;//千瓦时
焦耳是能量单位,我们听到比较多的是卡路里,饮料里面有多少卡的能量;千瓦时也比较常见,电脑一小时耗电多少
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:3600000000 unit:NSUnitEnergy.joules];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitEnergy.calories];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitEnergy.kilowattHours];
NSLog(@"%f",measurement1.doubleValue); // 860420650.095602
NSLog(@"%f",measurement2.doubleValue); // 1000.000000
Base unit - hertz 频率就是赫兹,简称 赫 先看参数
@property (class, readonly, copy) NSUnitFrequency *terahertz;//太赫
@property (class, readonly, copy) NSUnitFrequency *gigahertz;//千兆赫
@property (class, readonly, copy) NSUnitFrequency *megahertz;//兆赫
@property (class, readonly, copy) NSUnitFrequency *kilohertz;//千赫
@property (class, readonly, copy) NSUnitFrequency *hertz;//赫
@property (class, readonly, copy) NSUnitFrequency *millihertz;//毫赫
@property (class, readonly, copy) NSUnitFrequency *microhertz;//微赫
@property (class, readonly, copy) NSUnitFrequency *nanohertz;//纳米赫
代码的话很容易
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:72000 unit:NSUnitFrequency.hertz];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitFrequency.kilohertz];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitFrequency.millihertz];
NSLog(@"%f",measurement1.doubleValue); // 72.000000
NSLog(@"%f",measurement2.doubleValue); // 72000000.000000
Base unit - litersPer100Kilometers 每升100公里
@property (class, readonly, copy) NSUnitFuelEfficiency *litersPer100Kilometers;//每升100公里
@property (class, readonly, copy) NSUnitFuelEfficiency *milesPerImperialGallon;//英制加仑英里数
@property (class, readonly, copy) NSUnitFuelEfficiency *milesPerGallon;//英里每加仑
来段代码如下
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:16 unit:NSUnitFuelEfficiency.litersPer100Kilometers];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitFuelEfficiency.milesPerImperialGallon];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitFuelEfficiency.milesPerGallon];
NSLog(@"%f",measurement1.doubleValue); // 17.655062
NSLog(@"%f",measurement2.doubleValue); // 14.700938
Base unit - meters 基础单位米
@property (class, readonly, copy) NSUnitLength *megameters;//兆米(米制长度单位,=100万米)
@property (class, readonly, copy) NSUnitLength *kilometers;//千米
@property (class, readonly, copy) NSUnitLength *hectometers;//百米
@property (class, readonly, copy) NSUnitLength *decameters;//十米
@property (class, readonly, copy) NSUnitLength *meters;//米
@property (class, readonly, copy) NSUnitLength *decimeters;//分米
@property (class, readonly, copy) NSUnitLength *centimeters;//厘米
@property (class, readonly, copy) NSUnitLength *millimeters;//毫米
@property (class, readonly, copy) NSUnitLength *micrometers;//微米
@property (class, readonly, copy) NSUnitLength *nanometers;//纳米
@property (class, readonly, copy) NSUnitLength *picometers;//皮米
@property (class, readonly, copy) NSUnitLength *inches;//英寸
@property (class, readonly, copy) NSUnitLength *feet;//英尺(=12 英寸或 30.48 厘米)
@property (class, readonly, copy) NSUnitLength *yards;//码(等于3英尺或36英寸或0.9144米)
@property (class, readonly, copy) NSUnitLength *miles;//英里
@property (class, readonly, copy) NSUnitLength *scandinavianMiles;//斯堪的那维亚英里
@property (class, readonly, copy) NSUnitLength *lightyears;//光年
@property (class, readonly, copy) NSUnitLength *nauticalMiles;//海里
@property (class, readonly, copy) NSUnitLength *fathoms;//英寻
@property (class, readonly, copy) NSUnitLength *furlongs;//弗隆,浪(相当于0.2公里)
@property (class, readonly, copy) NSUnitLength *astronomicalUnits;//天文单位
@property (class, readonly, copy) NSUnitLength *parsecs;//秒差距
看下换算,这个比较简单
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:240 unit:NSUnitLength.meters];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitLength.yards];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitLength.furlongs];
NSLog(@"%f",measurement1.doubleValue); // 262.467192
NSLog(@"%f",measurement2.doubleValue); // 1.19303
Base unit - lux , 这货就一个属性,
勒克斯lux,法定符号lx)是照度(Illuminance)的单位。等于1流明(lumen)的光通量(Luminous flux)均匀照在1平方米表面上所产生的照度。适宜于阅读和缝纫等的照度约为60勒克斯
@property (class, readonly, copy) NSUnitIlluminance *lux;//勒克斯
然后,就是用法了。。
NSMeasurement *measurement1 = [[NSMeasurement alloc] initWithDoubleValue:90 unit:NSUnitIlluminance.lux];
NSMeasurementFormatter *formatter = [[NSMeasurementFormatter alloc] init];
[formatter setUnitOptions:NSMeasurementFormatterUnitOptionsProvidedUnit];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh"]];
NSLog(@"%@",[formatter stringFromMeasurement:measurement1]); // 90勒克斯
Base unit - kilograms 基础单位千克
@property (class, readonly, copy) NSUnitMass *kilograms;//千克
@property (class, readonly, copy) NSUnitMass *grams;//克
@property (class, readonly, copy) NSUnitMass *decigrams;//分克
@property (class, readonly, copy) NSUnitMass *centigrams;//厘克
@property (class, readonly, copy) NSUnitMass *milligrams;//毫克
@property (class, readonly, copy) NSUnitMass *micrograms;//微克
@property (class, readonly, copy) NSUnitMass *nanograms;//毫微克
@property (class, readonly, copy) NSUnitMass *picograms;//微微克
@property (class, readonly, copy) NSUnitMass *ounces;//盎司
@property (class, readonly, copy) NSUnitMass *poundsMass;//镑
@property (class, readonly, copy) NSUnitMass *stones;//英石(重量单位,合14磅)
@property (class, readonly, copy) NSUnitMass *metricTons;//吨
@property (class, readonly, copy) NSUnitMass *shortTons;//短吨
@property (class, readonly, copy) NSUnitMass *carats;//克拉
@property (class, readonly, copy) NSUnitMass *ouncesTroy;//金衡盎司
@property (class, readonly, copy) NSUnitMass *slugs;//斯勒格1slug=14.5939kg(质量单位)
来段代码搞一搞
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:240 unit:NSUnitMass.kilograms];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitMass.ounces];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitMass.poundsMass];
NSLog(@"%f",measurement1.doubleValue); // 8465.757774
NSLog(@"%f",measurement2.doubleValue); // 529.109861
Base unit - watts 瓦特 ,功率
@property (class, readonly, copy) NSUnitPower *terawatts;//兆兆瓦
@property (class, readonly, copy) NSUnitPower *gigawatts;//千兆瓦
@property (class, readonly, copy) NSUnitPower *megawatts;//兆瓦
@property (class, readonly, copy) NSUnitPower *kilowatts;//千瓦
@property (class, readonly, copy) NSUnitPower *watts;//瓦
@property (class, readonly, copy) NSUnitPower *milliwatts;//毫瓦
@property (class, readonly, copy) NSUnitPower *microwatts;//微瓦
@property (class, readonly, copy) NSUnitPower *nanowatts;//纳瓦
@property (class, readonly, copy) NSUnitPower *picowatts;//皮瓦
@property (class, readonly, copy) NSUnitPower *femtowatts;//毫微微瓦
@property (class, readonly, copy) NSUnitPower *horsepower;//马力
代码来一段
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:7500 unit:NSUnitPower.watts];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitPower.horsepower];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitPower.kilowatts];
NSLog(@"%f",measurement1.doubleValue); // 10.057664
NSLog(@"%f",measurement2.doubleValue); // 7.500000
Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) 牛顿每平方米 ,也就是压强
@property (class, readonly, copy) NSUnitPressure *newtonsPerMetersSquared;//牛每平方米
@property (class, readonly, copy) NSUnitPressure *gigapascals;//吉帕
@property (class, readonly, copy) NSUnitPressure *megapascals;//兆帕
@property (class, readonly, copy) NSUnitPressure *kilopascals;//千帕
@property (class, readonly, copy) NSUnitPressure *hectopascals;//百帕
@property (class, readonly, copy) NSUnitPressure *inchesOfMercury;//英寸汞柱
@property (class, readonly, copy) NSUnitPressure *bars;//巴
@property (class, readonly, copy) NSUnitPressure *millibars;//毫巴
@property (class, readonly, copy) NSUnitPressure *millimetersOfMercury;//毫米汞柱
@property (class, readonly, copy) NSUnitPressure *poundsForcePerSquareInch;//磅力每平方英寸
同样来段代码
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:75 unit:NSUnitPressure.bars];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitPressure.millimetersOfMercury];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitPressure.poundsForcePerSquareInch];
NSLog(@"%f",measurement1.doubleValue); // 56254.781656
NSLog(@"%f",measurement2.doubleValue); // 1087.782606
Base unit - metersPerSecond m/s
@property (class, readonly, copy) NSUnitSpeed *metersPerSecond;//米每秒
@property (class, readonly, copy) NSUnitSpeed *kilometersPerHour;//公里每小时
@property (class, readonly, copy) NSUnitSpeed *milesPerHour;//英里每小时
@property (class, readonly, copy) NSUnitSpeed *knots;//节 轮船速度
同样来段代码
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:100 unit:NSUnitSpeed.metersPerSecond];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitSpeed.knots];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitSpeed.kilometersPerHour];
NSLog(@"%f",measurement1.doubleValue); // 194.384617
NSLog(@"%f",measurement2.doubleValue); // 359.999712
Base unit - kelvin 开尔文
@property (class, readonly, copy) NSUnitTemperature *kelvin;//开氏温度
@property (class, readonly, copy) NSUnitTemperature *celsius; //摄氏温度
@property (class, readonly, copy) NSUnitTemperature *fahrenheit;//华氏温度
上代码了
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:100 unit:NSUnitTemperature.celsius];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitTemperature.kelvin];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitTemperature.fahrenheit];
NSLog(@"%f",measurement1.doubleValue); // 373.150000
NSLog(@"%f",measurement2.doubleValue); // 212.000000
Base unit - liters 升
@property (class, readonly, copy) NSUnitVolume *megaliters;//兆升
@property (class, readonly, copy) NSUnitVolume *kiloliters;//千升
@property (class, readonly, copy) NSUnitVolume *liters;//升
@property (class, readonly, copy) NSUnitVolume *deciliters;//分升
@property (class, readonly, copy) NSUnitVolume *centiliters;//厘升
@property (class, readonly, copy) NSUnitVolume *milliliters;//毫升
@property (class, readonly, copy) NSUnitVolume *cubicKilometers;//立方公里
@property (class, readonly, copy) NSUnitVolume *cubicMeters;//立方米
@property (class, readonly, copy) NSUnitVolume *cubicDecimeters;//立方分米
@property (class, readonly, copy) NSUnitVolume *cubicCentimeters;//立方厘米
@property (class, readonly, copy) NSUnitVolume *cubicMillimeters;//立方毫米
@property (class, readonly, copy) NSUnitVolume *cubicInches;//立方英寸
@property (class, readonly, copy) NSUnitVolume *cubicFeet;//立方英尺
@property (class, readonly, copy) NSUnitVolume *cubicYards;//立方码
@property (class, readonly, copy) NSUnitVolume *cubicMiles;//立方英里
@property (class, readonly, copy) NSUnitVolume *acreFeet;//英亩英尺
@property (class, readonly, copy) NSUnitVolume *bushels;//蒲式耳(2150.42立方英寸,或35.42升)
@property (class, readonly, copy) NSUnitVolume *teaspoons;//茶匙
@property (class, readonly, copy) NSUnitVolume *tablespoons;//汤匙
@property (class, readonly, copy) NSUnitVolume *fluidOunces;//液盎司
@property (class, readonly, copy) NSUnitVolume *cups;//杯
@property (class, readonly, copy) NSUnitVolume *pints;//品脱
@property (class, readonly, copy) NSUnitVolume *quarts;//夸脱
@property (class, readonly, copy) NSUnitVolume *gallons;//加仑
@property (class, readonly, copy) NSUnitVolume *imperialTeaspoons;//英制茶匙
@property (class, readonly, copy) NSUnitVolume *imperialTablespoons;//一大汤匙
@property (class, readonly, copy) NSUnitVolume *imperialFluidOunces;//英制液体盎司
@property (class, readonly, copy) NSUnitVolume *imperialPints;//英制品脱
@property (class, readonly, copy) NSUnitVolume *imperialQuarts;//英制夸脱
@property (class, readonly, copy) NSUnitVolume *imperialGallons;//英制加仑
@property (class, readonly, copy) NSUnitVolume *metricCups;//度量杯
还是来点代码,不然蛋疼了
NSMeasurement *measurement = [[NSMeasurement alloc] initWithDoubleValue:100 unit:NSUnitVolume.liters];
NSMeasurement *measurement1 = [measurement measurementByConvertingToUnit:NSUnitVolume.teaspoons];
NSMeasurement *measurement2 = [measurement measurementByConvertingToUnit:NSUnitVolume.gallons];
NSLog(@"%f",measurement1.doubleValue); // 20288.420181
NSLog(@"%f",measurement2.doubleValue); // 26.417218
over了 ,希望能用上。。。。