This is basically my code I have:
var myString: String?
var body: some View {
NavigationView {
if myString != nil {
CustomView(text: myString ?? "")
}
}
}
If I try without adding the ?? ""
part, it doesn't work, says Value of optional type 'String?' must be unwrapped to a value of type 'String'
. If I add it in as shown above, it seems to work, but why do I need to have a default empty string value if that's never going to be the case? (Since it will only reach that code if myString is not nil) Is there a way I can make this code more cleaner?