How to use Switch or If statements in a SwiftUI View

Yes! It would look something like this

EVERY code path must return a view, here there are 3

  • checking for small
  • checking for medium
  • else is if it isn’t either of those, it defaults to large
  • OR if you didn’t want that and check for large, the else could be an EmptyView() instead
HStack {
   Text(restaurant.name)

   if restaurant.size == "small" {
      Image(restaurant.image) //small image
   } else if restaurant.size == "medium" {
      Image(restaurant.image) // medium image
   } else {
      // must be a large image
      Image(restaurant.image) // large image
   }
}