作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用此变量将枚举转换为字符串:
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/
我是一名优秀的程序员,十分优秀!