小编htl*_*500的帖子

将NSTimInterval转换为Integer Swift

我需要将NSTimeInterval类型的变量(我知道是Double)转换为Integer.我已经尝试过这里的解决方案:如何将NSTimeInterval转换为int?,没有成功.任何人都可以在Swift中提供有关如何执行此操作的任何建议吗?以下是我的功能:

func getHKQuantityData(sampleType: HKSampleType, timeUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate, completion: (Void -> Void)) -> [(NSDate, Double)] {
    var startTime = 0
    var endTime = 0
    var repeat: NSTimeInterval
    var returnValue: [(NSDate, Double)] = []
    var queryType: String = ""
    var predicate: NSPredicate!
    let timeInterval = endDate.timeIntervalSinceDate(startDate)
    switch sampleType {
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount):
        queryType = "step"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight):
        queryType = "height"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass):
        queryType = "weight"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex):
        queryType = "bmi"
    default:
        println("No recognized type")
    }

    switch timeInterval { …
Run Code Online (Sandbox Code Playgroud)

nstimeinterval swift

6
推荐指数
1
解决办法
8949
查看次数

使用 HealthKit 的异常

我正在使用 Xcode 创建一个带有 HealthKit 的应用程序,但是每当我尝试在 iOS 模拟器中授权 HealthKit 时,它就会崩溃。我的代码在底部。有谁知道如何解决这一问题?

func authorizeHealthKit(completion: ((success:Bool, error:NSError!) -> Void)!)
  {
// 1. Set the types you want to read from HK Store
let healthKitTypesToRead = Set(arrayLiteral:[
  HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth),
  HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBloodType),
  HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight),
  HKObjectType.workoutType()
])

// 2. Set the types you want to write to HK Store
let healthKitTypesToWrite = Set(arrayLiteral:[
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning),
  HKQuantityType.workoutType()
])

// 3. If the store is not available (for instance, iPad) return an error and don't go on.
if !HKHealthStore.isHealthDataAvailable() …
Run Code Online (Sandbox Code Playgroud)

crash ios unrecognized-selector healthkit

2
推荐指数
1
解决办法
506
查看次数