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

Reading time: 1 min

When implementing a custom TextField by wrapping a UITextField in UIViewRepresentable (just like we did in our custom SecureField that tracks focus change, you need to be careful as its size normally grows with its content. This can lead to the field spilling outside the bounds of its parent...

Continue Reading...