Are you doing something dynamic that is related to the name on your app so you can show the correct one based on the selection?
If you are, I suggest you create your own local String enum and then add a var or function to get the blur from it instead of trying to reverse this.
But if you really, really need this for some other reason, there is a workaround, which I do not recommend, but it's here in case you want to test it out:
let blurStyle = String(describing: UIBlurEffect(style: .systemMaterialDark))
let style = blurStyle.components(separatedBy: "style=").last?.replacingOccurrences(of: "UIBlurEffectStyle", with: "")
print(style) // SystemMaterialDark
Creating your own app Style enum:
enum AppBlurStyle: String {
case extraLight
case dark
case light
case regular
var blurEffectStyle: UIBlurEffect.Style {
switch self {
case .extraLight: UIBlurEffect.Style.extraLight
case .dark: UIBlurEffect.Style.dark
case .light: UIBlurEffect.Style.light
case .regular: UIBlurEffect.Style.regular
}
}
var blurEffect: UIBlurEffect {
switch self {
case .extraLight: UIBlurEffect(style: .extraLight)
case .dark: UIBlurEffect(style:.dark)
case .light: UIBlurEffect(style:.light)
case .regular: UIBlurEffect(style:.regular)
}
}
}
Or you can even just extend UIBlurEffect.Style and add a name property, mapping them individually:
extension UIBlurEffect.Style {
var name: String {
switch self {
case .extraLight: "extraLight"
case .dark: "dark"
case .light: "light"
case .regular: "regular"
...
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…