【发布时间】:2021-01-22 17:43:11
【问题描述】:
我正在尝试以编程方式提取 UIBlurEffect.Style 的枚举案例的名称,其中 rawValue 的 Int 而不是 String。数组中的名称为["extraLight","light","dark","regular",...]
执行print(UIBlurEffect.Style.systemChromeMaterialLight) 不会打印systemChromeMaterialLight,而是打印UIBlurEffectStyle
我也尝试使用Mirror,但这会产生__C.UIBlurEffectStyle的名称
我正在尝试做的示例代码:
let myStyles : [UIBlurEffect.Style] = [.light, .dark, .regular, .prominent]
for style in myStyles {
print(style) // does not work, produces "UIBlurEffectStyle"
myFunction(styleName: String(reflecting: style)) // does not work, produces "UIBlurEffectStyle"
myFunction(styleName: String(describing: style)) // does not work, produces "UIBlurEffectStyle"
myFunction(styleName: "\(style)") // does not work, produces "UIBlurEffectStyle"
}
我正在使用 Swift 5、iOS 14 和 Xcode 12.3
供参考,枚举由Apple定义如下:
extension UIBlurEffect {
@available(iOS 8.0, *)
public enum Style : Int {
case extraLight = 0
case light = 1
case dark = 2
@available(iOS 10.0, *)
case regular = 4
...
【问题讨论】:
-
@impression7vx 不起作用
-
可能必须为每个案例制作一个
switch声明,然后您可以简单地调用描述。 stackoverflow.com/a/52077091/5009432