gpt4 book ai didi

ios - 如何将 HKBloodType 枚举转换为字符串

转载 作者:行者123 更新时间:2023-11-30 14:13:35 25 4
gpt4 key购买 nike

我需要使用此变量将枚举转换为字符串:

var bloodType:HKBloodTypeObject? = healthKitStore.bloodTypeWithError(&error);

这个枚举:

enum HKBloodType : Int {
case NotSet
case APositive
case ANegative
case BPositive
case BNegative
case ABPositive
case ABNegative
case OPositive
case ONegative
}

我知道还有其他类似的问题,但我还没有找到任何适合我的答案。

最佳答案

简单描述:HKBloodTypeObject 作为 HealthKit 存储中 HKBloodType 参数的包装器。

extension HKBloodTypeObject {
func string()->String {
switch self.bloodType {
case .abNegative:
return "AB-"
case .abPositive:
return "AB+"
case .aNegative:
return "A-"
case .aPositive:
return "A+"
case .bNegative:
return "B-"
case .bPositive:
return "B+"
case .oNegative:
return "O-"
case .oPositive:
return "O+"
default:
return "Not Set"
}
}
}

使用 HKBloodType 枚举扩展的最佳方式。希望上面的代码行能够帮助您。

关于ios - 如何将 HKBloodType 枚举转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31485281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com