表达式类型模糊,没有更多上下文Healthkit ios Swift

时间:2016-06-22 10:24:43

标签: ios swift swift2 health-kit

我正在关注This教程使用HealthKit,我收到标题中所述的错误

到目前为止,这是我的代码。

import Foundation
import UIKit
import HealthKit

class YASHealthKitManager {
let healthKitStore:HKHealthStore = HKHealthStore()    
class func authorizeHealthKit(completion: ((success:Bool, error:NSError!) -> Void)!)
{
    let healthKitTypesToRead  : [String : AnyObject] = Set(arrayLiteral:[

        HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth),
        HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBloodType),
        HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight),
        HKObjectType.workoutType()
        ])

    let healthKitTypesToWrite = Set(arrayLiteral:[
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning),
        HKQuantityType.workoutType()
        ])

    if !HKHealthStore.isHealthDataAvailable()
    {
        let error = NSError(domain: "com.raywenderlich.tutorials.healthkit", code: 2, userInfo: [NSLocalizedDescriptionKey:"HealthKit is not available in this Device"])
        if( completion != nil )
        {
            completion(success:false, error:error)
        }
        return;
    }

    // 4.  Request HealthKit authorization
    healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { (success, error) -> Void in

        if( completion != nil )
        {
            completion(success:success,error:error)
        }
    }
}

}

这是错误的屏幕截图

enter image description here

我不知道代码有什么问题,因为我只是从教程中复制了它。

1 个答案:

答案 0 :(得分:1)

Set(arrayLiteral: [a, b, c])更改为Set(arrayLiteral: a, b, c)