HealthKit composite data for HealthKit development tutorials

Source: Internet
Author: User
Tags ming

HealthKit composite data for HealthKit development Tutorials

composite data is data composed of composite units and values. The so-called composite Unit is the unit for multiplication, division and other units obtained, such as m/s,lb· ft and so is the compound unit. This section will explain these composite data.

HealthKit'smultiply the resulting composite data

in physics, we may have been exposed to similar lb · ft (torque unit, torque is a special torque that causes the object to rotate.) ) such a unit. This unit can be seen as a compound unit multiplied by two units. Developers who want to use this compound unit in their own programs first need to create this unit. Creating such a unit requires the use of the Unitmultipliedbyunit (_:) method, which has the following syntax:

    • Func Unitmultipliedbyunit (_ unit:hkunit!), hkunit!

where the parameters Unit : Used to specify the units to be multiplied.

The example 2-44 : Hkunit-unitmultipliedbyunit "The following shows the torque of the generator in the car, to" lbs . feet "is the unit. The code is as follows:

  • Import UIKit

  • Import HealthKit

  • Class Viewcontroller:uiviewcontroller {

  • Override Func Viewdidload () {

  • Super.viewdidload ()

  • Additional setup after loading the view, typically from a nib.

  • & nbsp         var footunit = Hkunit.footunit ()                                                                                           // Create length units

  • & nbsp       var poundunit=hkunit.poundunit ()                                                                                   // Create mass units

  • var unitmultipliedbyunit=footunit.unitmultipliedbyunit (poundunit) // multiply the resulting compound units

  • var myforce=hkquantity (Unit:unitmultipliedbyunit, doublevalue:100)

  • println (" the torque of the generator in the car is:\ (myforce)")

  • }

  • ......

  • }

When you run the program, you see the following effect.

    • the torque of the generator in the car is: lb · ft

HealthKit'sdivide the resulting composite data

in mathematical calculations, we often encounter m/S such a unit. This unit is divided into two units. If the developer wants to use this unit in their own code. You first need to use the Unitdividedbyunit (_:) method to create this unit, with the following syntax:

    • Func Unitdividedbyunit (_ unit:hkunit!), hkunit!

where the parameters _ Unit used to specify the unit, which is used as a divisor.

The example 2-45 : Hkunit-unitdividedbyunit The following shows the speed at which the user runs, in meters / seconds "is the unit. The code is as follows:

  • Import UIKit

  • Import HealthKit

  • Class Viewcontroller:uiviewcontroller {

  • Override Func Viewdidload () {

  • Super.viewdidload ()

  • Additional setup after loading the view, typically from a nib.

  • & nbsp       Let meters = Hkunit.meterunit ()                                                                       // Create length units

  • Let seconds = hkunit.secondunit ()// Create a time unit

  • Let Meterspersecond = meters.unitdividedbyunit (seconds)// dividing the resulting compound units

  • Let Speed=hkquantity (Unit:meterspersecond, Doublevalue:2)

  • println (" Xiao Ming runs at speed:\")

  • }

  • ......

  • }

When you run the program, you see the following effect.

    • Xiao Ming runs at the speed of: 2 m/s

HealthKit'scompound data consisting of units and integers in the sub-square

in terms of volume and area, we will use the M3 , m2 such units. This unit is a composite unit composed of units and the sub-party of integers. If developers want to create such a unit, they need to use the Unitraisedtopower (_:) method, which has the following syntax:

    • Func Unitraisedtopower (_ Power:int), hkunit!

where the parameters Power is an integer that is used to specify the secondary side.

The example 2-46 : Hkunit-unitraisedtopower "The volume of the basin is shown below , in cubic meters." the code is as follows:

  • Import UIKit

  • Import HealthKit

  • Class Viewcontroller:uiviewcontroller {

  • Override Func Viewdidload () {

  • Super.viewdidload ()

  • Additional setup after loading the view, typically from a nib.

  • var meters = Hkunit.meterunit ()

  • var cubicmeter=meters.unitraisedtopower (3)// A compound unit of a unit and a sub-square of integers

  • var pool=hkquantity (Unit:cubicmeter, doublevalue:100)

  • println (" Pool size:\ (Pool)")

  • }

  • ......

  • }

When you run the program, you see the following effect.

    • the volume of the pool is: m^3

HealthKit'sa compound unit of reciprocal composition

1/s This unit is a "Hertz" unit, which represents the 1 the frequency at which a cycle process occurs within a second time interval. A unit similar to 1/s is composed of the reciprocal of a unit. If you want to use this unit in your program, you need to use the reciprocalunit () method. the function of the reciprocalunit () method is to construct a new compound unit by the inverse of the unit. Its grammatical form is as follows:

    • Func reciprocalunit ()-hkunit!

The example 2-47 : Hkunit-reciprocalunit The following shows the 1 The frequency at which a cycle process occurs within the seconds interval to " 1/ seconds "is the unit. The code is as follows:

  • Import UIKit

  • Import HealthKit

  • Class Viewcontroller:uiviewcontroller {

  • Override Func Viewdidload () {

  • Super.viewdidload ()

  • Additional setup after loading the view, typically from a nib.

  • var seconds = Hkunit.secondunit ()

  • var secondsinverse = seconds.reciprocalunit () // a compound unit consisting of the reciprocal

  • var frequency=hkquantity (Unit:secondsinverse, doublevalue:50)

  • println (" the frequency of a cycle process occurring within a 1-second interval is:\ (Frequency)")

  • }

  • ......

  • }

When you run the program, you see the following effect.

    • in the 1 the frequency at which a cycle process occurs within a second interval is: 1/s

This article is selected from: HealthKit Development Quick Start Tutorial University PA information, reproduced Please indicate the source, respect the technology respect the IT person!


HealthKit composite data for HealthKit development tutorials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.