From 8b37e03d4ca9eb9de644b75e39a5240af7a12a87 Mon Sep 17 00:00:00 2001 From: Philip Zhang Date: Sat, 27 May 2023 16:47:33 -0700 Subject: [PATCH] optional binding fix --- ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift b/ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift index 4a079c34..8ba4778e 100644 --- a/ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift +++ b/ALUM/ALUM/Views/EditProfile/EditMentorProfile.swift @@ -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) } @@ -228,6 +228,14 @@ struct EditMentorProfileScreen: View { } } +// Overload the ?? operator to support binding String? (with default value) to String +func ?? (lhs: Binding, rhs: T) -> Binding { + Binding( + get: { lhs.wrappedValue ?? rhs }, + set: { lhs.wrappedValue = $0 } + ) +} + struct EditMentorProfileScreen_Previews: PreviewProvider { static var previews: some View { EditMentorProfileScreen(uID: "6431b9a2bcf4420fe9825fe5")