读/写到健康工具包未转换为Xcode 7:如何修复'type of expression is ambiguous without more context'错误?



当我从Xcode 6转换为Xcode 7时,读取和写入HK存储时,在以下行中出现错误"表达式类型不明确,没有更多上下文":'let healthKitTypesToRead=Set(arrayLiteral:[]和'let heahealthKittypesToWrite=Set(arryLiteral:["

// 1. Set the types you want to read from HK Store
let healthKitTypesToRead = Set(arrayLiteral:[
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate),
  HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
  ])
// 2. Set the types you want to write to HK Store
let healthKitTypesToWrite = Set(arrayLiteral:[
   HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
  ])

我如何修复这个红色警报错误,或者写替代代码来读/写到香港商店?

我刚刚解决了。'QuantityTypeForIdentifier需要更改为characteristicTypeForIdentifier',以及其他一些格式更改:

  {
// 1. Set the types you want to read from HK Store
let healthKitTypesToRead = Set(arrayLiteral:
  HKObjectType.characteristicTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!,
  HKObjectType.characteristicTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!
)
// 2. Set the types you want to write to HK Store
let healthKitTypesToWrite = Set(arrayLiteral:
  HKObjectType.characteristicTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!
  )

相关内容

最新更新