Umair Afzal
Umair Afzal

Reputation: 5039

Expression Type ambiguous without more context Healthkit ios Swift

I am following This tutorial to use HealthKit and I am getting error as stated in the title

This is my code so far.

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)
        }
    }
}

}

and here is the screenshot of the error

enter image description here

I do not have an idea what is wrong with the code because i just copied it from the tutorial.

Upvotes: 0

Views: 157

Answers (1)

Code
Code

Reputation: 6251

Change Set(arrayLiteral: [a, b, c]) to Set(arrayLiteral: a, b, c).

Upvotes: 1

Related Questions