I've found that the get and set closures for Binding seem to help with optional values. Below, the Binding for the username property uses the nil-coalescing operator (??) to provide an empty string as a default value when tempUser.username is nil. The set block handles setting the tempUser.username property, ensuring it becomes nil if the new value is an empty string.
private var username: Binding<String> {
Binding(
get: {
self.tempUser.username ?? ""
},
set: { newName in
self.tempUser.username = newName.isEmpty ? nil : newName
}
)
}