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...

Reading time: 2 min

This recipe shows all you need to do to support dark mode in your SwiftUI app. The end result looks like this:

preview

You should know that SwiftUI supports dark mode by default - which can be a blessing and a curse. Basically, if you're building a simple app without a lot of custom styling, most th...

Continue Reading...

Reading time: 1 min

This recipe shows how to change or remove row padding (insets) in SwiftUI List. The end result looks like this:

preview

To make this happen, use the listRowInsets modifier on the List content view. Don't place the modifier on the List itself or its superviews, or else it won't work.

@State p...

Continue Reading...