Integrate SwiftUI (Automatic)
Overview
The LuciqSwiftUIIntegrator is a powerful command-line tool designed to automatically instrument SwiftUI applications for enhanced user experience monitoring and debugging capabilities. This tool modifies your SwiftUI source code during the build process to add instrumentation code that tracks user interactions and screen navigation.
The instrumentor adds additional code to your project's Swift files (*.swift) during the build process to observe UI element states and user interactions. After the build process completes, all changes to your source code are automatically reverted, ensuring your original code remains unchanged.
Requirements
SwiftUI 2.0+
Luciq SDK integrated in your project
Xcode build environment
Features
Supported SwiftUI Controls
Button - Tracks button taps
Toggle - Monitors toggle state changes
Slider - Captures slider value changes
Stepper - Tracks stepper increment/decrement actions
NavigationLink - Monitors navigation events
TabView - Tracks tab selection changes
Supported Modifiers
The tool also instruments the following SwiftUI modifiers:
onTapGesture - Captures tap gestures on views
sheet - Tracks sheet presentation and dismissal
popover - Monitors popover interactions
fullScreenCover - Captures full screen cover presentations
navigationDestination - Tracks navigation destination changes
Instrumentation Capabilities
Screen Name Tracking - Automatically extracts and tracks screen/view names
User Interaction Monitoring - Captures user interactions with UI elements
Privacy Masking - Supports masking sensitive UI components
Automatic Reversion - Reverts all code changes after build completion
Screen Transitions Tracking
The tool automatically observes SwiftUI view transitions and navigation events to capture performance metrics and relevant screenshots. This includes transitions triggered by:
.sheet
.popover
.fullScreenCover
NavigationLink
navigationDestination
TabView index changes
Installation & Setup
Prerequisites
Ensure that the Luciq SDK is already integrated into your project before using the SwiftUI instrumentor.
Integration Steps
Download LuciqSwiftUIIntegrator You can download the instrumentor file from here.
Add the Instrumentor to Your Build Process Add the LuciqSwiftUIIntegrator as a pre-build phase in your Xcode project:
Configure Build Settings The tool automatically handles build environment detection and will skip simulator builds by default unless explicitly enabled.
Command Reference
Basic Usage
Available Actions
instrument(Default) Performs complete instrumentation of both screen names and user interactions.CMDDescription: This is the most comprehensive action that instruments your SwiftUI views to extract both screen names and user interaction events.
screen_namesInstruments the project to extract only screen names.Description: Focuses specifically on tracking navigation and screen identification without instrumenting user interactions.
user_interactionInstruments the project to extract only user interaction events.revertManually reverts all instrumentation changes.
Description: Manually cleans up and reverts all changes made by the instrumentor. Normally, this happens automatically after the build.
Command Options
Directory Path
Specifies the project's base directory path. Defaults to current directory (.).
Example:
Blacklist Files
Excludes specific files from instrumentation.
Example:
Masked Types
Specifies SwiftUI view types to be automatically masked for privacy.
Example:
Enable Simulator
Enables instrumentation for simulator builds (disabled by default).
Example:
Disable Diff Tracking
Disables keeping track of changes made to source code.
Example:
Disable Logging
Disables internal debug logs of the tool.
Example:
Version
Prints the version of the tool.
Example:
Configuration Examples
Basic Project Instrumentation
Privacy-Focused Configuration
Screen Tracking Only
Development Build Configuration
Integration with Xcode Build Process
Pre-Build Script Phase
Add a new "Run Script" phase in your Xcode target's Build Phases:
Conditionally Skip Instrumentation
After testing out the script, you can add checks to optimize build time in debug builds. The following snippet skips the instrumentation for debug builds, and you can manually disable instrumentation for CI builds by setting ENABLE_LUCIQ_SWIFTUI to NO.
How It Works
Instrumentation Process
File Discovery: The tool recursively searches for all .swift files in the specified directory
Syntax Analysis: Each Swift file is parsed to identify SwiftUI views
Code Rewriting: Supported SwiftUI elements are wrapped with tracking code
Import Injection: Adds necessary import statements (import LuciqSDK)
Backup Creation: Creates backup files (.backup extension) of original source
Automatic Reversion: Monitors build completion and automatically reverts changes
Privacy Masking
When a view type is specified in --masked-types, the tool wraps those views with privacy masking:
CMD
User Interaction Tracking
The tool enhances user interaction callbacks with tracking code:
Known Limitations
SwiftUI Version Support
SwiftUI 2.0+ only: The instrumentor requires iOS 14+ deployment target
Custom SwiftUI controls: Currently doesn't support instrumentation of custom SwiftUI components
Build Performance Impact
Increased build time: The instrumentation process adds overhead to build time
File processing: Each Swift file must be parsed and potentially rewritten
Reversion
Reversion process is not executed: This happens if the build process is terminated from Xcode before the build finishes.
Simulator Builds
Disabled by default: Simulator instrumentation is disabled by default to optimize development builds
Manual enabling: Use
--enable-simulatorflag to enable for simulator builds
Troubleshooting
Common Issues
Build Failures
If the instrumentor causes build failures:
Check that all blacklisted files are correctly specified
Ensure the Luciq SDK is properly integrated
Verify iOS deployment target is 14.0 or higher
Please reach out to our support team with the tool’s debug logs file. The file is located at
{PROJECT_DIR}/LuciqInstrumentation/changeLogsFile.log
Performance Issues
If builds are too slow:
Use selective actions (
screen_namesoruser_interactioninstead ofinstrument)Disable simulator instrumentation
Add frequently changing files to the blacklist
Privacy Concerns
For sensitive applications:
Use
--masked-typesto automatically mask sensitive view typesBlacklist files containing sensitive information
Review instrumented code in development builds before release
Debug Information
The tool provides comprehensive logging.
Views being instrumented
Errors and warnings
Reversion process
Getting Help
Best Practices
Development Workflow
Test incrementally: Start with
screen_namesoruser_interactionbefore using fullinstrumentUse blacklists: Exclude test files, mock files, and frequently changing development files
Monitor build times: Track build performance impact and adjust configuration as needed
Production Builds
Release configuration: Only enable instrumentation for release builds or specific configurations
Privacy masking: Always configure appropriate masking for sensitive data
Validation: Test instrumented builds thoroughly before release
CI/CD Integration
Conditional execution: Use environment variables to control when instrumentation runs
Caching: Consider caching strategies for the instrumentor binary and dependencies
Build logs: Capture and analyze instrumentation logs for debugging
The LuciqSwiftUIIntegrator provides a powerful way to enhance your SwiftUI applications with comprehensive user experience monitoring while maintaining the flexibility to customize the instrumentation process to your specific needs.
Last updated