### Define Basic Analytics Client Structure Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift code defines a AnalyticsClient struct, which includes a track function for handling events and a nested Event struct. It serves as a foundational example for demonstrating dependency injection and testing strategies. ```Swift struct AnalyticsClient { var track: (Event) -> Void struct Event: Equatable { var name: String var properties: [String: String] } } ``` -------------------------------- ### Parent Model Providing Callback Implementation Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Shows how a `ParentModel` instantiates `ChildModel` and provides the concrete implementation for the `onDelete` closure. This setup ensures the parent feature performs the actual deletion logic when the child requests it. ```Swift class ParentModel { var child: ChildModel? func presentChildButtonTapped() { child = ChildModel(onDelete: { // Parent feature performs deletion logic }) } } ``` -------------------------------- ### Handle Complex Dependencies with XCTUnimplemented and Placeholders Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift example demonstrates XCTUnimplemented's versatility with a more complex AppDependencies struct. It shows how to use XCTUnimplemented for methods that throw or require return values, including the optional placeholder parameter for default values. ```Swift struct AppDependencies { var date: () -> Date = Date.init, var fetchUser: (User.ID) async throws -> User, var uuid: () -> UUID = UUID.init } extension AppDependencies { static let unimplemented = Self( date: XCTUnimplemented("\(Self.self).date", placeholder: Date()), fetchUser: XCTUnimplemented("\(Self.self).fetchUser"), uuid: XCTUnimplemented("\(Self.self).uuid", placeholder: UUID()) ) } ``` -------------------------------- ### Initialize ViewModel with Analytics Dependency Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift snippet shows the LoginViewModel's initializer, which accepts an AnalyticsClient as a dependency. This pattern promotes testability by allowing different implementations of the analytics client to be injected during testing. ```Swift class LoginViewModel: ObservableObject { // ... init(analytics: AnalyticsClient) { // ... } // ... } ``` -------------------------------- ### Test Login Flow with Buffered Analytics Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift test function demonstrates how to test a login flow by providing a custom AnalyticsClient that buffers events into an array. This allows the test to assert on the exact events tracked without sending them to a live analytics service. ```Swift func testLogin() { var events: [AnalyticsClient.Event] = [] let viewModel = LoginViewModel( analytics: .test { events.append($0) } ) // ... XCTAssertEqual(events, [.init(name: "Login Success")]) } ``` -------------------------------- ### Add XCTestDynamicOverlay as SPM Package Dependency Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Specifies the dependency in a Swift Package Manager's Package.swift file, pointing to the XCTestDynamicOverlay repository and a minimum version. This is the first step to integrate the library into your project. ```Swift .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"), ``` -------------------------------- ### Add IssueReporting Product to Target Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Adds the 'IssueReporting' product from the 'xctest-dynamic-overlay' package as a dependency to a specific target within a Swift Package Manager project. This makes the library's functionalities available to your application or module. ```Swift .target( "MyTarget", dependencies: [ .product(name: "IssueReporting", package: "xctest-dynamic-overlay") ] ) ``` -------------------------------- ### Simplify Unimplemented Client with XCTUnimplemented Helper Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift extension shows how to use the XCTUnimplemented helper from XCTestDynamicOverlay to concisely define the unimplemented static instance. This helper automatically creates a failing closure, reducing boilerplate code. ```Swift extension AnalyticsClient { static let unimplemented = Self( track: XCTUnimplemented("\(Self.self).track") ) } ``` -------------------------------- ### Override Callback After Child Model Creation Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Illustrates how the `onDelete` closure can be assigned after the `ChildModel` is instantiated. This approach addresses the initialization restriction but introduces a potential for laxness, as the callback might be forgotten. ```Swift func presentChildButtonTapped() { child = ChildModel() child.onDelete = { // Parent feature performs deletion logic } } ``` -------------------------------- ### Issue Reporting Library API Reference Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Core API elements for the Issue Reporting library, including the primary function for reporting issues, available issue reporter types, and methods for overriding reporting behavior. This section details the main components developers interact with. ```APIDOC Function: reportIssue(_:fileID:filePath:line:column:) Purpose: Primary tool for reporting an issue in application code. Usage: Invoke from anywhere to signal an unexpected event. Default Behavior: Triggers an unobtrusive, purple runtime warning in Xcode. Protocol: IssueReporter Purpose: Defines the interface for custom issue reporting mechanisms. Requirement: reportIssue(_:fileID:filePath:line:column:) Purpose: Implement to define custom issue reporting logic. Enum/Static Properties: IssueReporter runtimeWarning: Purpose: Default reporter. Issues reported as purple runtime warnings in Xcode; printed to console elsewhere. breakpoint: Purpose: Triggers a breakpoint, stopping app execution for debugging. fatalError: Purpose: Raises a fatal error, permanently stopping app execution. Function: withIssueReporters(_:operation:) Purpose: Temporarily overrides issue reporters for a lexical scope. Parameters: reporters: An array of IssueReporter instances to use for the scope. operation: A closure containing the code for which reporters are overridden. Example Usage: - withIssueReporters([]) { ... } // Disable reporting - withIssueReporters(IssueReporters.current + [.breakpoint]) { ... } // Add breakpoint reporter Static Variable: IssueReporters.current Purpose: Globally controls the active issue reporters. Usage: Typically set at the application's entry point (e.g., App init). Type: [IssueReporter] Example Usage: IssueReporters.current = [.fatalError] ``` -------------------------------- ### Integrate XCTestDynamicOverlay for Unimplemented Client Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift code block demonstrates how XCTestDynamicOverlay enables defining both the AnalyticsClient and its unimplemented static instance within the same application target. This eliminates the need for separate test support modules, simplifying project structure. ```Swift struct AnalyticsClient { var track: (Event) -> Void struct Event: Equatable { var name: String var properties: [String: String] } } import XCTestDynamicOverlay extension AnalyticsClient { static let unimplemented = Self( track: { _ in XCTFail("\(Self.self).track is unimplemented.") } ) } ``` -------------------------------- ### Temporarily Disable Issue Reporting Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Shows how to use `withIssueReporters([])` to temporarily disable all issue reporting within a specific lexical scope. Any issues raised inside this block will not be reported. ```Swift withIssueReporters([]) { // Any issues raised here will not be reported. } ``` -------------------------------- ### Create Unimplemented Analytics Client with XCTFail Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift extension defines an unimplemented static instance of AnalyticsClient. When its track method is called, it triggers an XCTFail, ensuring that tests which should not track analytics will fail, providing strong guarantees. ```Swift import XCTest extension AnalyticsClient { static let unimplemented = Self( track: { _ in XCTFail("\(Self.self).track is unimplemented.") } ) } ``` -------------------------------- ### Deep Linking Problem with Required Callback Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Demonstrates a scenario, such as deep linking, where providing the `onDelete` closure at `ChildModel` initialization is problematic or unclear. This highlights the inflexibility of strictly requiring the callback during instantiation. ```Swift import SwiftUI @main struct MyApp: App { var body: some Scene { ParentView( model: ParentModel( child: ChildModel(onDelete: { /* ??? */ }) ) ) } } ``` -------------------------------- ### Child Model with Unimplemented Callback Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Shows the recommended solution using `unimplemented("onDelete")` from the library. This allows the closure to be optional at initialization but reports an issue if invoked without being overridden, balancing strictness and flexibility. ```Swift @Observable class ChildModel { var onDelete: () -> Void = unimplemented("onDelete") // ... } ``` -------------------------------- ### Test Validation with Unimplemented Analytics Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Articles/GettingStarted.md This Swift test function illustrates how to use the unimplemented analytics client. By injecting this client, the test can verify that no analytics events are tracked during the validation process, making the test suite more robust. ```Swift func testValidation() { let viewModel = LoginViewModel( analytics: .unimplemented ) // ... } ``` -------------------------------- ### Report an Issue with reportIssue Function Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Demonstrates how to use the `reportIssue` function to signal an unexpected condition in application code. When invoked, it triggers a runtime warning in Xcode by default, providing visual feedback without stopping execution. ```Swift guard let lastItem = items.last else { reportIssue("'items' should never be empty.") return } // ... ``` -------------------------------- ### Define Child Model with Required Callback Closure Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Illustrates a `ChildModel` that requires an `onDelete` callback closure to communicate with its parent. The `deleteButtonTapped` method invokes this closure, demonstrating a common pattern for inter-feature communication. ```Swift @Observable class ChildModel { var onDelete: () -> Void func deleteButtonTapped() { onDelete() } } ``` -------------------------------- ### Temporarily Add Breakpoint Issue Reporter Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Illustrates how to add the `breakpoint` issue reporter to the current set of reporters for a specific lexical scope. Issues reported within this block will trigger a breakpoint, allowing for immediate debugging. ```Swift withIssueReporters(IssueReporters.current + [.breakpoint]) { // Any issues reported here will trigger a breakpoint } ``` -------------------------------- ### Child Model with Optional Empty Callback Default Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Presents a modification to `ChildModel` where `onDelete` is given an empty default closure. This makes the callback optional during initialization but can lead to subtle bugs if the closure is not overridden and is later invoked. ```Swift @Observable class ChildModel { var onDelete: () -> Void = {} // ... } ``` -------------------------------- ### Globally Override Issue Reporters in App Init Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md Demonstrates how to globally set the issue reporter to `fatalError` within the `init` method of a SwiftUI `App` struct. This ensures that all reported issues throughout the application's lifecycle will cause a fatal error, stopping execution. ```Swift import IssueReporting import SwiftUI @main struct MyApp: App { init() { IssueReporters.current = [.fatalError] } var body: some Scene { // ... } } ``` -------------------------------- ### XCTestDynamicOverlay XCTFail Function API Reference Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Extensions/XCTFail.md Provides an overview of the `XCTFail` function within the `XCTestDynamicOverlay` module, detailing its overloads and associated context. ```APIDOC Function: XCTestDynamicOverlay/XCTFail(_:file:line:) Topics: Overloads: - XCTFail(_:) Context: - XCTFailContext ``` -------------------------------- ### Importing XCTest Directly Causes Build Errors Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/XCTestDynamicOverlay.md Directly importing the XCTest framework into application or library source files leads to linker warnings and prevents the target from building. This is due to conflicts with test header search paths and linker configurations, making XCTest incompatible with regular production code compilation. ```swift import XCTest // 🛑 ld: warning: Could not find or use auto-linked library 'XCTestSwiftSupport' // 🛑 ld: warning: Could not find or use auto-linked framework 'XCTest' ``` -------------------------------- ### XCTestDynamicOverlay API Reference Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/XCTestDynamicOverlay.md This section outlines the core API functions provided by XCTestDynamicOverlay, categorized into assertion overlays and unimplemented dependency handlers. These functions allow for dynamic XCTest assertions and placeholder implementations within application and library code. ```APIDOC Overlays: XCTFail(_:file:line:) XCTExpectFailure(_:enabled:strict:failingBlock:issueMatcher:) Unimplemented dependencies: unimplemented(_:placeholder:fileID:line:)-70bno unimplemented(_:fileID:line:)-7znj2 ``` -------------------------------- ### API Documentation for withIssueReporters Function Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/withIssueReporters.md Details the `withIssueReporters` function and its overload, outlining their signatures and purpose. ```APIDOC Function: IssueReporting/withIssueReporters(_:operation:) Description: Executes an operation with issue reporters. Overload: withIssueReporters(_:isolation:operation:) Description: Executes an operation with issue reporters, specifying an isolation level. ``` -------------------------------- ### IssueReporting/withIssueContext API Reference Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/withIssueContext.md Detailed API reference for the `withIssueContext` function, including its parameters and available overloads. ```APIDOC IssueReporting/withIssueContext(fileID:filePath:line:column:operation:) Topics: Overloads: withIssueContext(fileID:filePath:line:column:isolation:operation:) ``` -------------------------------- ### Configure Swift Test Target for Release Mode Issue Reporting Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Articles/ReleaseMode.md This Swift Package Manager configuration snippet demonstrates how to link the 'IssueReportingTestSupport' product to a test target. By adding this dependency, the 'IssueReporting' library can correctly trigger test failures even when the test suite is run in release mode. It is crucial to only link this product to test targets and never to app targets, as doing so will lead to linker errors. ```Swift .testTarget( name: "FeatureTests", dependencies: [ "Feature", .product(name: "IssueReportingTestSupport", package: "swift-issue-reporting") ] ) ``` -------------------------------- ### API Documentation for `IssueReporting/withExpectedIssue` Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/withExpectedIssue.md Provides the signature and an overload for the `withExpectedIssue` function, part of the `IssueReporting` module, including inferred parameter types and descriptions. ```APIDOC Function: IssueReporting/withExpectedIssue Signature: (_:isIntermittent:fileID:filePath:line:column:_:) -> Void Parameters: _: (Any) - An unnamed parameter, typically a closure or block of code to execute. isIntermittent: (Bool) - A boolean indicating if the issue is intermittent. fileID: (String) - The file identifier where the issue is reported. filePath: (String) - The full path to the file where the issue is reported. line: (Int) - The line number in the file where the issue is reported. column: (Int) - The column number in the file where the issue is reported. _: (Any) - An unnamed parameter, typically a closure or block of code to execute. Overload: Function: IssueReporting/withExpectedIssue Signature: (_:isIntermittent:isolation:fileID:filePath:line:column:_:) -> Void Parameters: _: (Any) - An unnamed parameter, typically a closure or block of code to execute. isIntermittent: (Bool) - A boolean indicating if the issue is intermittent. isolation: (Any) - An isolation context, type unknown from context (e.g., actor isolation). fileID: (String) - The file identifier where the issue is reported. filePath: (String) - The full path to the file where the issue is reported. line: (Int) - The line number in the file where the issue is reported. column: (Int) - The column number in the file where the issue is reported. _: (Any) - An unnamed parameter, typically a closure or block of code to execute. ``` -------------------------------- ### API Documentation for unimplemented Function Overloads (Swift) Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/Unimplemented.md Documents the various overloads of the `unimplemented` function, which is part of the `IssueReporting` module. These functions are typically used in Swift projects to indicate code paths that are not yet implemented, often for testing or placeholder purposes. ```APIDOC Function: unimplemented Purpose: Marks a code path as unimplemented. Overloads: - unimplemented(_:fileID:filePath:function:line:column:) - unimplemented(_:fileID:filePath:function:line:column:) - unimplemented(_:throwing:fileID:filePath:function:line:column:) - unimplemented(_:throwing:fileID:filePath:function:line:column:) - unimplemented(_:placeholder:fileID:filePath:function:line:column:) - unimplemented(_:placeholder:fileID:filePath:function:line:column:) ``` -------------------------------- ### IssueReporting/IssueReporter API Reference Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/IssueReporter.md Defines the structure and members of the `IssueReporting/IssueReporter` interface, including methods for issue reporting and available reporter types. ```APIDOC IssueReporting/IssueReporter: Topics: Conforming to report issues: - reportIssue(_:fileID:filePath:line:column:) - expectIssue(_:fileID:filePath:line:column:)-8ooca Available reporters: - runtimeWarning - breakpoint - fatalError ``` -------------------------------- ### Using XCTestDynamicOverlay to Resolve XCTest Import Issues Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/XCTestDynamicOverlay.md The XCTestDynamicOverlay library provides a workaround for the XCTest import problem. By importing XCTestDynamicOverlay instead of XCTest, the library dynamically loads the XCTFail symbol at runtime, allowing its use from any part of the application or library code without causing compilation or linking errors. This dynamic loading is restricted to DEBUG builds to prevent App Store rejections. ```swift import XCTestDynamicOverlay // ✅ ``` -------------------------------- ### API Reference: XCTestDynamicOverlay Unimplemented Dependencies Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/XCTestDynamicOverlay/Documentation.docc/Extensions/Deprecations.md This section lists deprecated API symbols related to unimplemented dependencies within the XCTestDynamicOverlay framework. These symbols indicate functionality that is no longer supported or recommended for use and should be replaced with current alternatives. ```APIDOC unimplemented(_:file:fileID:line:)-7w4sd unimplemented(_:file:fileID:line:)-dh05 unimplemented(_:file:fileID:line:)-74vrh XCTUnimplemented(_:)-36h59 XCTUnimplemented(_:)-8fvli XCTUnimplemented(_:file:line:)-7xjl4 XCTUnimplemented(_:file:line:)-69z9t XCTUnimplemented(_:placeholder:)-9rrxn XCTUnimplemented(_:placeholder:)-71986 XCTUnimplementedFailure ``` -------------------------------- ### API Documentation for UnimplementedFailure Structure (Swift) Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/Unimplemented.md Documents the `UnimplementedFailure` structure, which is likely associated with the `unimplemented` function. This structure probably represents the type of failure or error that occurs when an unimplemented code path is encountered. ```APIDOC Structure: UnimplementedFailure Purpose: Represents a failure state related to unimplemented code. ``` -------------------------------- ### IssueReporter.expectIssue Protocol Method Signature Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/IssueReporter.expectIssue.md This entry documents the `expectIssue` method, part of the `IssueReporter` protocol. It is designed to be called when an issue is expected, providing context such as the file, line, and column where the expectation is made. This method is crucial for structured issue reporting within testing frameworks. ```APIDOC Protocol: IssueReporter Method: expectIssue(_:fileID:filePath:line:column:) Parameters: _ : Any (The issue or message to be reported) fileID: String (The name of the file where the issue occurred) filePath: String (The full path to the file where the issue occurred) line: Int (The line number in the file where the issue occurred) column: Int (The column number in the file where the issue occurred) Returns: Void (This method does not return a value) ``` -------------------------------- ### Report Issue with reportIssue in Swift Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/IssueReporting.md Demonstrates how to use the `reportIssue` function to flag an issue in Swift code, such as an unexpected empty collection. By default, this triggers an unobtrusive Xcode runtime warning, providing a visible way to identify issues without interrupting app execution. ```swift guard let lastItem = items.last else { reportIssue("'items' should never be empty.") return } // ... ``` -------------------------------- ### IssueReporting.reportIssue API Definition Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/Sources/IssueReporting/Documentation.docc/Extensions/reportIssue.md Defines the `reportIssue` function, which is used to report errors or issues within an application, capturing precise source code location details like file ID, file path, line, and column numbers. ```APIDOC Function: IssueReporting.reportIssue(_:_:fileID:filePath:line:column:) Description: Reports an issue with detailed source location information. Parameters: - name: (unnamed parameter 1) description: The primary issue or message to be reported. type: Any (inferred) - name: (unnamed parameter 2) description: Additional context or a closure providing further details for the report. type: Any (inferred) - name: fileID description: A unique identifier for the source file where the issue occurred. type: String - name: filePath description: The full path to the source file where the issue occurred. type: String - name: line description: The line number within the source file where the issue occurred. type: Int - name: column description: The column number within the line in the source file where the issue occurred. type: Int Returns: Void ``` -------------------------------- ### Report Issue with `reportIssue` Function in Swift Source: https://github.com/pointfreeco/xctest-dynamic-overlay/blob/main/README.md Demonstrates the basic usage of the `reportIssue` function to flag an issue in Swift code, such as an unexpected empty collection. This function, by default, triggers an unobtrusive purple runtime warning in Xcode, providing visual feedback without stopping the app's execution. ```Swift guard let lastItem = items.last else { reportIssue("'items' should never be empty.") return } … ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.