Font.Weight to String in SwiftUI

Hi,

In SwiftUI, I'm trying to show Text of Font.Weight value.

How to convert from Font.Weight type to String?

Thanks in advance.
Answered by BabyJ in 642042022
Font.Weight doesn’t have the rawValue property so you can’t access it like this:
Code Block Swift
Font.Weight.bold.rawValue // bold

You could create your own enum that does have this feature:
Code Block Swift
extension Font {
enum <#Weight#>: String, CaseIterable, Equatable, Hashable {
// add all cases from Font.Weight
}
}

Beware though that Apple could add or remove cases from Font.Weight.
Accepted Answer
Font.Weight doesn’t have the rawValue property so you can’t access it like this:
Code Block Swift
Font.Weight.bold.rawValue // bold

You could create your own enum that does have this feature:
Code Block Swift
extension Font {
enum <#Weight#>: String, CaseIterable, Equatable, Hashable {
// add all cases from Font.Weight
}
}

Beware though that Apple could add or remove cases from Font.Weight.
Font.Weight to String in SwiftUI
 
 
Q