### Full Wormholy Configuration Example Source: https://context7.com/pmusolino/wormholy/llms.txt Combines multiple configuration options for a typical debug setup in an `AppDelegate` or SwiftUI `App` entry point. Includes ignored hosts, request limits, default filters, shake control, and enabling/disabling interception for specific session configurations. ```swift import SwiftUI @main struct MyApp: App { init() { configureWormholy() } var body: some Scene { WindowGroup { ContentView() } } private func configureWormholy() { #if DEBUG // Suppress noise from analytics and auth services Wormholy.ignoredHosts = ["firebase.io", "analytics.google.com", "crashlytics.com"] // Retain the last 200 requests Wormholy.limit = 200 // Pre-filter to the main API on open Wormholy.defaultFilter = "api.myapp.com" // Disable shake (using a custom debug menu button instead) Wormholy.shakeEnabled = false // Ensure global interception is on Wormholy.setEnabled(true) // Disable for the payment session specifically let paymentConfig = URLSessionConfiguration.ephemeral Wormholy.setEnabled(false, sessionConfiguration: paymentConfig) #endif } } ``` -------------------------------- ### Install Wormholy with CocoaPods Source: https://github.com/pmusolino/wormholy/blob/master/README.md Install Wormholy for debug builds only. Ensure it is removed before sending your app to production. ```shell pod 'Wormholy', :configurations => ['Debug'] ``` -------------------------------- ### Install Wormholy with CocoaPods (Debug Only) Source: https://context7.com/pmusolino/wormholy/llms.txt Use this configuration in your Podfile to ensure Wormholy is only included in debug builds. This is the recommended installation method. ```ruby # Podfile pod 'Wormholy', :configurations => ['Debug'] ``` -------------------------------- ### Install Wormholy with Swift Package Manager Source: https://context7.com/pmusolino/wormholy/llms.txt Add Wormholy as a dependency in your Xcode project or Package.swift file. Ensure it's removed before App Store submission. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/pmusolino/Wormholy.git", from: "2.4.0") ], targets: [ .target( name: "MyApp", dependencies: ["Wormholy"]) ] ``` -------------------------------- ### Configure Wormholy Options Source: https://github.com/pmusolino/wormholy/blob/master/README.md Set ignored hosts, logging limit, default filter, and enable/disable global tracking. Session-specific configurations can also be managed. ```swift func configureWormholy() { Wormholy.ignoredHosts = ["example.com", "analytics.internal"] Wormholy.limit = 200 Wormholy.defaultFilter = "status:500" Wormholy.shakeEnabled = true // Global tracking for URLSession traffic. Wormholy.setEnabled(true) // Use the session-specific API when you want to override behavior // for a particular configuration instance. let configuration = URLSessionConfiguration.default Wormholy.setEnabled(false, sessionConfiguration: configuration) let session = URLSession(configuration: configuration) _ = session } ``` -------------------------------- ### Configure Ignored Hosts with Suffix Matching Source: https://github.com/pmusolino/wormholy/blob/master/README.md Set ignored hosts using suffix matching. Requests to the specified domain and its subdomains will be ignored. ```swift Wormholy.ignoredHosts = ["example.com"] ``` -------------------------------- ### Configure Ignored Hosts Source: https://context7.com/pmusolino/wormholy/llms.txt Set `Wormholy.ignoredHosts` to an array of host suffixes to prevent interception of traffic to those domains. Matching uses `hasSuffix`, affecting subdomains as well. You can later modify this array to remove hosts or reset it to capture all traffic. ```swift // Ignore analytics pings and internal health-check endpoints Wormholy.ignoredHosts = [ "analytics.example.com", // exact subdomain "crashlytics.com", // all crashlytics traffic "internal.corp" // internal domain (matches sub.internal.corp too) ] // Later, allow a previously ignored host by removing it Wormholy.ignoredHosts.removeAll { $0 == "crashlytics.com" } // Reset to capture everything Wormholy.ignoredHosts = [] ``` -------------------------------- ### Set Default Search Filter in Swift Source: https://context7.com/pmusolino/wormholy/llms.txt Pre-populates the search field in the `RequestsView` inspector. Useful for focusing on a specific endpoint or domain as soon as the panel opens. ```swift // Always open Wormholy pre-filtered to 5xx responses Wormholy.defaultFilter = "500" // Focus on a particular API path Wormholy.defaultFilter = "/api/v2/orders" // Clear the default so the search field starts blank Wormholy.defaultFilter = nil ``` -------------------------------- ### Wormholy.ignoredHosts Source: https://context7.com/pmusolino/wormholy/llms.txt Configures an array of host suffixes to be excluded from network request recording. Requests to hosts ending with any of these suffixes will not be captured. ```APIDOC ## Wormholy.ignoredHosts ### Description An array of host suffixes to exclude from recording. Matching uses `hasSuffix`, so `"example.com"` also suppresses subdomains such as `api.example.com`. ### Property `static var ignoredHosts: [String]` ### Parameters None ### Request Example ```swift // Ignore analytics pings and internal health-check endpoints Wormholy.ignoredHosts = [ "analytics.example.com", // exact subdomain "crashlytics.com", // all crashlytics traffic "internal.corp" // internal domain (matches sub.internal.corp too) ] // Later, allow a previously ignored host by removing it Wormholy.ignoredHosts.removeAll { $0 == "crashlytics.com" } // Reset to capture everything Wormholy.ignoredHosts = [] ``` ### Response #### Success Response (Array of Strings) - **ignoredHosts** ([String]) - An array containing host suffixes that are ignored. #### Response Example ```swift // Get current ignored hosts let currentIgnored = Wormholy.ignoredHosts print(currentIgnored) ``` ``` -------------------------------- ### Wormholy.setEnabled(_:sessionConfiguration:) Source: https://context7.com/pmusolino/wormholy/llms.txt Injects or removes `CustomHTTPProtocol` from the `protocolClasses` array of a specific `URLSessionConfiguration`. This allows opting individual sessions in or out of interception, regardless of the global flag. ```APIDOC ## Wormholy.setEnabled(_:sessionConfiguration:) ### Description Injects or removes `CustomHTTPProtocol` from the `protocolClasses` array of a specific `URLSessionConfiguration` before the session is created. Use this to opt individual sessions in or out regardless of the global flag. ### Method `static func setEnabled(_ enabled: Bool, sessionConfiguration: URLSessionConfiguration)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift // Disable Wormholy for a session that handles sensitive payment data let paymentConfig = URLSessionConfiguration.ephemeral Wormholy.setEnabled(false, sessionConfiguration: paymentConfig) let paymentSession = URLSession(configuration: paymentConfig) // Enable for a custom background-like config (note: true background sessions // are not supported by Apple's URLProtocol injection mechanism) let apiConfig = URLSessionConfiguration.default Wormholy.setEnabled(true, sessionConfiguration: apiConfig) let apiSession = URLSession(configuration: apiConfig) // Verify global state print(Wormholy.isWormholyEnabled()) // true ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example None ``` -------------------------------- ### Per-Session Wormholy Enable/Disable Source: https://context7.com/pmusolino/wormholy/llms.txt Use `Wormholy.setEnabled(_:sessionConfiguration:)` to control interception for specific `URLSessionConfiguration` instances. This allows opting individual sessions in or out, regardless of the global setting. Note that true background sessions are not supported. ```swift // Disable Wormholy for a session that handles sensitive payment data let paymentConfig = URLSessionConfiguration.ephemeral Wormholy.setEnabled(false, sessionConfiguration: paymentConfig) let paymentSession = URLSession(configuration: paymentConfig) // Enable for a custom background-like config (note: true background sessions // are not supported by Apple's URLProtocol injection mechanism) let apiConfig = URLSessionConfiguration.default Wormholy.setEnabled(true, sessionConfiguration: apiConfig) let apiSession = URLSession(configuration: apiConfig) // Verify global state print(Wormholy.isWormholyEnabled()) // true ``` -------------------------------- ### Limit Request Log Size in Swift Source: https://context7.com/pmusolino/wormholy/llms.txt Caps the number of requests retained in memory. When the cap is exceeded, the oldest entry is dropped. Set to `nil` for unlimited. ```swift // Keep only the last 100 requests to bound memory usage Wormholy.limit = 100 // For long-running QA sessions, increase the ceiling Wormholy.limit = 500 // Remove the cap entirely Wormholy.limit = nil ``` -------------------------------- ### Manually Open Wormholy Inspector via Notification Source: https://context7.com/pmusolino/wormholy/llms.txt Opens the Wormholy inspector from any point in the app without a shake gesture. Useful when testing on devices where shaking is impractical, or when building a custom debug menu. ```swift // Add a debug button to your settings screen Button("Open Network Inspector") { NotificationCenter.default.post( name: NSNotification.Name(rawValue: "wormholy_fire"), object: nil ) } // Or trigger from a long-press gesture recognizer let longPress = UILongPressGestureRecognizer(target: self, action: #selector(openDebugMenu)) view.addGestureRecognizer(longPress) @objc func openDebugMenu() { NotificationCenter.default.post( name: NSNotification.Name(rawValue: "wormholy_fire"), object: nil ) } // Expected: Wormholy's RequestsView slides up as a page sheet. ``` -------------------------------- ### Export Request as Plain Text Source: https://context7.com/pmusolino/wormholy/llms.txt Provides a detailed plain-text breakdown of a captured request, including overview, headers, and body. This is one of Wormholy's export formats accessible from the inspector's share menu. ```text # Plain-text export format per request: # *** Overview *** # URL: https://api.myapp.com/v1/login # Method: POST # Response Code: 200 # Request Start Time: Jan 5 2025 - 14:32:01 # Duration: 312ms # ... # *** Request Header *** # Content-Type: application/json # ... # *** Response Body *** # { "token": "eyJhbGci..." } ``` -------------------------------- ### Wormholy.isWormholyEnabled() Source: https://context7.com/pmusolino/wormholy/llms.txt Checks and returns the current global enabled state of Wormholy's network request interception. ```APIDOC ## Wormholy.isWormholyEnabled() ### Description Returns the current global enabled state. Also exposed to Objective-C (used internally by `NSURLSessionConfiguration+Wormholy`). ### Method `static func isWormholyEnabled() -> Bool` ### Parameters None ### Request Example ```swift func configureAnalytics() { guard Wormholy.isWormholyEnabled() else { print("Wormholy is off — skipping network debug setup") return } // Safe to configure debug-only tooling Wormholy.defaultFilter = "analytics" } ``` ### Response #### Success Response (Bool) - **enabled** (Bool) - `true` if Wormholy is globally enabled, `false` otherwise. #### Response Example ```swift // Example usage within a function: func setupNetworkDebugging() { if Wormholy.isWormholyEnabled() { print("Wormholy is active.") } else { print("Wormholy is not active.") } } ``` ``` -------------------------------- ### Export Request as cURL Command Source: https://context7.com/pmusolino/wormholy/llms.txt The `curlRequest` computed property on `RequestModel` reconstructs a captured network request into a runnable cURL command. This is one of Wormholy's export formats. ```shell # curlRequest output example (generated internally by RequestModel.curlRequest): # $ curl -v \ # -X POST \ # -H "Content-Type: application/json" \ # -H "Authorization: Bearer eyJhbGci..." \ # -d "{\"username\":\"alice\",\"password\":\"s3cret\"}" \ # "https://api.myapp.com/v1/login" ``` -------------------------------- ### Control Shake Gesture in Swift Source: https://context7.com/pmusolino/wormholy/llms.txt Controls whether shaking the device/simulator opens the inspector. Can also be set via the `WORMHOLY_SHAKE_ENABLED` environment variable in an Xcode scheme. ```swift // Disable shake so the UI can only be opened programmatically Wormholy.shakeEnabled = false // Re-enable shake (e.g., after a tutorial flow completes) Wormholy.shakeEnabled = true ``` ```bash WORMHOLY_SHAKE_ENABLED = NO ``` -------------------------------- ### Export Requests as Postman Collection Source: https://context7.com/pmusolino/wormholy/llms.txt Wormholy automatically builds a Postman v2.1 collection JSON from captured requests. This can be triggered from the `RequestsView` toolbar and saves a `.json` file. ```json # Postman v2.1 collection JSON is built automatically from captured requests. # Trigger export from within the RequestsView toolbar: # Menu → "Share filtered as Postman" → saves a .json file named: # _-postman_collection.json ``` -------------------------------- ### Wormholy.setEnabled(_:) Source: https://context7.com/pmusolino/wormholy/llms.txt Globally enables or disables network request interception for all `NSURLSession` traffic. When enabled, `CustomHTTPProtocol` is registered to capture requests. This method does not affect the shake gesture for opening the UI. ```APIDOC ## Wormholy.setEnabled(_:) ### Description Registers or unregisters `CustomHTTPProtocol` as a global `URLProtocol`, turning request interception on or off for all subsequent `URLSession` traffic. Does not affect the shake gesture. ### Method `static func setEnabled(_ enabled: Bool)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { #if DEBUG // Explicitly enable (already on by default, shown for clarity) Wormholy.setEnabled(true) #else // Disable in release builds as an extra safety guard Wormholy.setEnabled(false) #endif return true } } ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example None ``` -------------------------------- ### Check Wormholy Global Status Source: https://context7.com/pmusolino/wormholy/llms.txt Use `Wormholy.isWormholyEnabled()` to retrieve the current global enabled state of the network interception. This is also accessible from Objective-C. ```swift func configureAnalytics() { guard Wormholy.isWormholyEnabled() else { print("Wormholy is off — skipping network debug setup") return } // Safe to configure debug-only tooling Wormholy.defaultFilter = "analytics" } ``` -------------------------------- ### Disable Wormholy for Specific Session Configuration Source: https://github.com/pmusolino/wormholy/blob/master/README.md Explicitly enable or disable Wormholy for a specific URLSessionConfiguration instance before creating the URLSession. ```swift let configuration = URLSessionConfiguration.ephemeral Wormholy.setEnabled(false, sessionConfiguration: configuration) let session = URLSession(configuration: configuration) ``` -------------------------------- ### Trigger Wormholy Manually with Notification Source: https://github.com/pmusolino/wormholy/blob/master/README.md Post the 'wormholy_fire' notification to trigger Wormholy manually from another part of your app. This is an alternative to the shake gesture. ```swift NotificationCenter.default.post(name: NSNotification.Name(rawValue: "wormholy_fire"), object: nil) ``` -------------------------------- ### Globally Enable Wormholy Interception Source: https://context7.com/pmusolino/wormholy/llms.txt Call `Wormholy.setEnabled(true)` in your AppDelegate to enable network request interception for all `NSURLSession` traffic in debug builds. It's enabled by default, but explicit calls improve clarity. Disable in release builds. ```swift import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { #if DEBUG // Explicitly enable (already on by default, shown for clarity) Wormholy.setEnabled(true) #else // Disable in release builds as an extra safety guard Wormholy.setEnabled(false) #endif return true } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.