Reading time: 2 min

This recipe shows how to combine ScrollViewReader and onChange(of:perform:) to jump to the selected item in a scrollable view. We'll use this method to update our top tabs and make them fully visible when selected. You can see the end result here:

Both the ScrollViewReader and onC...

Continue Reading...

Reading time: 1 min

This recipe shows how to implement an indefinite loading bar in SwiftUI. This kind of view is common in Android Material Design as it's sleek and takes up less space than a conventional, circular LoadingView. The end result looks like this:

The code for this is quite simple:

  1. Render a Re...

Continue Reading...

Reading time: 3 min

This recipe shows how to implement a swipeable pager view in SwiftUI. The end result will look like this:

Preview

A pager view lays its child views out as pages - single, currently selected child view occupies the entire pager. The user can swipe left or right to move through different pages.

First...

Continue Reading...

Reading time: 1 min

This recipe shows how to implement a timer in SwiftUI in order to update the UI state at a specific interval.

There are two ways of going about it:

  1. The simple one, with onReceive.
  2. A bit more complex, but also more powerful one, using SimpleTimer wrapper.

Direct updates with onReceiv...

Continue Reading...

Reading time: 3 min

Here's a quick tip for resolving a common and annoying error that you'll occasionally see. The error message is

Function declares an opaque return type, but the return statements in its body do not have matching underlying types

and you can see it if you declare a function or a property that...

Continue Reading...