Post

Replies

Boosts

Views

Activity

Reply to SwiftUI seems to assume that no one uses optionals anymore.
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 } ) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to SwiftUI NavigationLink freezing when tapped
Adding .id(UUID()) to my NavigationLink (inside a NavigationStack) worked for me. I would love to know the reason behind this issue and will be watching for a solution. I am on iOS 18.2 but had no problems on iOS 17.5.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’25
Reply to SwiftUI seems to assume that no one uses optionals anymore.
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 } ) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’24