I am trying to do something that was simple to me in UIKit - but cannot get working in SwiftUI.
I am pulling data from an API. That data is dynamic - some parts of the call may not be present every time. I have protected the app by making all of that data optional and using a nil operator to return "N/A" in the text fields where there is no data. In UIKit I was able to simple use an if statement:
if self.cityLabel.text == "N/A" {
self.cityLabel.isHidden = true
}
Now in SwiftUI, I have the following:
HStack() {
Text(self.model?.city ?? "N/A")
}
When the data is present, it displays without any issue. However, I am not sure where to access this property or put an if statement because this data is in a View class and does not accept functions.
So basically, how do I hide that text and have the blocks around it "move up" (like display: none) in HTML while in SwiftUI? How can I implement if statements in the View code?
I'm sure it's probably simple, but assistance would be much appreciated! :)