2016-06-22 8 views
0

私はHealthKitを使用するThisチュートリアルを以下だとこれはこれまでのところ私のコードであるタイトル式のタイプHealthkit IOSスウィフト

に述べたように、私はエラーを取得しています。

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

Set(arrayLiteral: [a, b, c])からSet(arrayLiteral: a, b, c)に変更してください。

+0

ああ、それは働いた。答えを教えてください。 –

+0

@UmairAfzal Swift 1と2の間で構文が変更されました。このチュートリアルは旧式です。 – Code

+0

私はそれを理解していますが、配列にはこれらの[]権利が含まれている必要がありますか? –

関連する問題