Reading time: 1 min

This recipe shows how to set visibility of a SwiftUI view. You can show it, hide it, or remove it from the view hierarchy entirely. The end result looks like this:

preview

We'll adopt a good practice from Android and model the view visibility like this:

enum ViewVisibility: CaseIterable {
  case v...

Continue Reading...

Reading time: 3 min

This recipe shows how to play videos in SwiftUI. It also shows how to add more advanced functionality, such as playing a sequence of videos, adding loop playback and custom end actions. The end result looks like this:

preview

If you wish to know more about what happens in that video, visit th...

Continue Reading...

Reading time: 1 min

This quick recipe shows how to set a @StateObject in a SwiftUI View's initializer. Basically, you're trying to do this:

struct MyView: View {
  @StateObject private var viewModel: ViewModel

  init(someParams: String) {
    viewModel = ViewModel(params: someParams)
  } 

But you keep running i...

Continue Reading...

Reading time: 1 min

This recipe shows how to add disclosure indicator to your SwiftUI List rows. The end result looks like this:

preview

The disclosure indicator is added automatically whenever your list row contains a NavigationLink, but sometimes you wish render the indicator and have a custom action when the row is...

Continue Reading...

Reading time: 7 min

This recipe shows how to add custom row swipe actions to a SwiftUI List, supporting multiple custom buttons on either side, as well as full swipe functionality. The end result looks like this:

preview

The solution depends on which SwiftUI version you have to support:

  1. SwiftUI 3 (iOS 15, macOS 12...

Continue Reading...