Anyone know if SwiftUI support ternary conditionals? I have a text view with conditional argument (Text(badgeCount == nil ? " " :"\(badgeCount!)")) that displays an empty view. Surprisingly, it works if I remove the @State attribute from the view.
import SwiftUI
struct RedBadgeView: View {
@State var badgeCount: Int?
init (_ badgeCount: Int? = nil) {
self.badgeCount = badgeCount
}
var body: some View {
// Something about this Syntax is throwing off SwiftUI.
Text(badgeCount == nil ? " " :"\(badgeCount!)")
}
}
struct RedBadgeView_Previews: PreviewProvider {
static var previews: some View {
RedBadgeView(1)
}
}