Skip to content

Commit

Permalink
optional binding fix
Browse files Browse the repository at this point in the history
  • Loading branch information
petabite committed May 27, 2023
1 parent 4c598d9 commit 8b37e03
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ struct EditMentorProfileScreen: View {

ALUMTextFieldComponent(title: "Calendly Access Token",
suggestion: "ey...",
text: $mentor.personalAccessToken,
text: $mentor.personalAccessToken ?? "",
isSecure: true)

ALUMTextFieldComponent(title: "Zoom Link",
suggestion: "eg. https://ucsd.zoom.us/t/1234567890",
text: $mentor.zoomLink)
text: $mentor.zoomLink ?? "")
}
.padding(.top, 20)
}
Expand Down Expand Up @@ -228,6 +228,14 @@ struct EditMentorProfileScreen: View {
}
}

// Overload the ?? operator to support binding String? (with default value) to String
func ?? <T>(lhs: Binding<T?>, rhs: T) -> Binding<T> {
Binding(
get: { lhs.wrappedValue ?? rhs },
set: { lhs.wrappedValue = $0 }
)
}

struct EditMentorProfileScreen_Previews: PreviewProvider {
static var previews: some View {
EditMentorProfileScreen(uID: "6431b9a2bcf4420fe9825fe5")
Expand Down

0 comments on commit 8b37e03

Please sign in to comment.