Files
2023-04-09 08:34:41 -04:00

2.2 KiB

PulseUI

A set of components that you can integrate into your app to view the logs.

Overview

The easiest way to integrate PulseUI is by using ConsoleView.

// On iOS
.sheet(isPresented: $isConsolePresented) {
    NavigationView {
        ConsoleView()
            .navigationBarItems(leading: Button("Close") {
                isConsolePresented = false
            })
    }
}

tip: If you use Pulse to log only network requests, and not text messages, use ConsoleView.network() to show a view specialized to only display network requests.

UIKit

To present the console from UIKit, use UIHostingController:

let view = NavigationView { 
    ConsoleView()
}
present(UIHostingController(rootView: view), animated: true)

If you are using appearance to change the navigation bar isTranslucent property to false, make sure to set extendedLayoutIncludesOpaqueBars to true:

let vc = UIHostingController(rootView: ConsoleView())
vc.extendedLayoutIncludesOpaqueBars = true
let nav = UINavigationController(rootViewController: vc)
nav.navigationBar.prefersLargeTitles = true
present(nav, animated: true)

Custom Views

PulseUI gives you complete access to the underlying data and its model. You can easily create custom views into your log data by using affordances provided by SwiftUI:

struct AnalyticsLogsView: View {
    @FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \LoggerMessageEntity.createdAt, ascending: true)],
        predicate: NSPredicate(format: "label == %@", "analytics")
    ) var messages: FetchedResults<LoggerMessageEntity>
    
    var body: some View {
        List(messages, id: \.objectID) { message in
            VStack(alignment: .leading) {
                Text(timeFormatter.string(from: message.createdAt))
                    .font(.footnote)
                    .foregroundColor(.secondary)
                Text(message.text)
                    .lineLimit(2)
            }
        }
    }
}

private let timeFormatter = DateFormatter(format: "HH:mm:ss.SSS")

Topics

Main Views

  • ConsoleView
  • SettingsView

Deprecated

  • MainViewController
  • MainView
  • NetworkView
  • PinsView