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

Reading time: 1 min

Here's a quick recipe for getting the key window, top or root View Controller, in a scene-based SwiftUI app:

extension UIApplication {
  var currentKeyWindow: UIWindow? {
    UIApplication.shared.connectedScenes
      .filter { $0.activationState == .foregroundActive }
      .map { $0 as? UIWind...

Continue Reading...

Reading time: 1 min

This tutorial shows how to add Android-like top tabs in SwiftUI. The result will look something like this:

Without much ado, here's the code for the component:

struct Tabs: View {
  @Binding var tabs: [String] // The tab titles
  @Binding var selection: Int // Currently selected...

Continue Reading...

Reading time: 1 min

This tutorial shows how to use SVG images in SwiftUI.

First, add the Macaw library to your project. Then, wrap its SVGView using this simple UIViewRepresentable wrapper:

import Macaw

struct SVGImage: UIViewRepresentable {
  // a binding allows for dynamic updates to the shown image
  @B...

Continue Reading...