HomeDocumentationAPI Reference
Getting StartedAPI ReferenceBug ReportingCrash ReportingAPMHelp Center

SwiftUI Integration for iOS

This guide provides instructions on how to integrate Instabug's Bug Reporting, Crash Reporting, and App Performance Monitoring features in your SwiftUI application. Following these steps, you can capture and report bugs and crashes from your SwiftUI application.

📘

We currently only support one method to detect SwiftUI screen names.

Define Screen Names

To track and identify screens in your SwiftUI app, you‘ll need to define screen names using the InstabugTraceView function. The screen name will correspond to the current view in your app, and Instabug will use the latest UI component to update screens.

Approach 1: Wrapping Instabug on your views

Wrap Instabug around each view you have in your app by using the following:

var body: some View {
      InstabugTracedView(name: "View Name") {
        VStack {
          Text("Hello, World!")
      }
  }
}

Approach 2: Appending Instabug to your views

This is achieved by doing the following:

  1. Call an API on the view that you want to make the root view.
  2. Using the API below, it will create you a new view and wrap the user view with a traced view.

Example:

var body: some View {
    VStack {
        Text("Hello, World!")
    }
    .instabugTracedView(name: "View Name")
}

Private Views

You can easily mark any SwiftUI view that might contain sensitive information, like payment details, as private. Any private view will automatically appear with a black overlay covering it in any screenshot.

To make a view private, you can use one of the following methods:

  • Method 1:
InstabugPrivateView {
  Text("Hello, World") 
}
  • Method 2:
Text("Hello, World")
     .instabug_privateView()

User Interactions - Manual Approach

To manually log user interactions on SwiftUI screens, you need to use the below API. The logged interactions will reflect in the Repro Steps and User Steps components.

UserStep(event: .tap)  
            .setMessage("Hello, World")  
            .setViewType(.text)  
            .logUserStep()

Properties in the API:

  • Event: User action on the screen (Ex. Tap, scroll..)
  • Message: A brief message to help in identifying the UI element (Ex. Sign in)
  • View Type: the type of the Ui element (Ex. Button, dropdown, text..)