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

This tutorial shows how to customize the navigation bar buttons as images. It applies to both the back button, as well as the button on the right-hand side. The end result will look something like this:

Customized navigation bar buttons

To do so, use the navigationBarItems(leading:trailing) method. As always, the navigation...

Continue Reading...

Reading time: 1 min

This recipe is about how to scroll a SwiftUI ScrollView programatically. Here's a quick breakdown of what to do:

  • For iOS 13 - tough luck - it can't be done. For whatever reason, this is one of things that were deemed less important for the initial release of SwiftUI.
  • For iOS 14 and abov...

Continue Reading...