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

Reading time: 1 min

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

The view uses SF Symbols, allowing it to scale to any size and render in any color. It supports an arbitrary upper limit for the rating and automatically rounds to nearest half.

Here's...

Continue Reading...

Reading time: 2 min

This recipe shows how to add a TextField to a SwiftUI alert dialog. The end result looks like this:

The dialog supports:

  1. Custom title and message.
  2. Text field with a placeholder and keyboard type.
  3. Confirm button, whose callback returns the content of the text field.
  4. Optiona...

Continue Reading...