### Setup AppKit Snapshot Trigger Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Use `setup(view:)` or `setup(viewController:)` with an `NSView` or `NSViewController` respectively. Snapshots are rendered with Retina support. Optional: refresh snapshots on hot-reload. ```swift import AppKit import XcodebuildNvimPreview import Combine @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var cancellables = Set() func applicationDidFinishLaunching(_ notification: Notification) { let contentVC = DashboardViewController() // Capture snapshot for Neovim preview XcodebuildNvimPreview.setup(viewController: contentVC) // Optional: refresh snapshot on Inject hot-reload observeHotReload() .sink { XcodebuildNvimPreview.setup(view: DashboardViewController().view) } .store(in: &cancellables) } } // Direct NSView usage: // let customView = DashboardView(frame: .zero) // XcodebuildNvimPreview.setup(view: customView) // PNG written to /tmp/xcodebuild.nvim/.png (Retina-aware) ``` -------------------------------- ### Setup UIKit Preview Source: https://github.com/wojciech-kulik/xcodebuild-nvim-preview/blob/main/README.md Sets up UIKit views for previewing with xcodebuild.nvim. Optionally enables hot reload using Inject. ```swift import XcodebuildNvimPreview func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // ... XcodebuildNvimPreview.setup(view: MainView()) // (optional) enable hot reload for preview (requires integration with `Inject`) observeHotReload() .sink { XcodebuildNvimPreview.setup(view: HomeView()) } .store(in: &cancellables) return true } ``` -------------------------------- ### Setup SwiftUI Preview Source: https://github.com/wojciech-kulik/xcodebuild-nvim-preview/blob/main/README.md Integrates SwiftUI views with xcodebuild.nvim for previewing. Supports hot reload. ```swift import SwiftUI import XcodebuildNvimPreview @main struct MyApp: App { var body: some Scene { WindowGroup { MainView() .setupNvimPreview { HomeView() } } } } ``` -------------------------------- ### Setup UIKit Snapshot with Hot Reload Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt This UIKit setup captures an initial PNG snapshot of a UIView for Neovim preview and optionally re-captures it on Inject hot-reloads. Ensure the `XcodebuildNvimPreview` framework is imported. ```swift import UIKit import XcodebuildNvimPreview import Combine @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var cancellables = Set() func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { let rootVC = HomeViewController() window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = rootVC window?.makeKeyAndVisible() // Capture initial snapshot for Neovim preview XcodebuildNvimPreview.setup(view: rootVC.view) // Optional: re-capture on every Inject hot-reload observeHotReload() .sink { XcodebuildNvimPreview.setup(view: HomeViewController().view) } .store(in: &cancellables) return true } } // Convenience overload – pass the view controller directly // XcodebuildNvimPreview.setup(viewController: rootVC) // Snapshot is written to /tmp/xcodebuild.nvim/.png ``` -------------------------------- ### Detect Preview Mode with `isInPreview` Flag Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Use the static `isInPreview` boolean property to conditionally execute preview-only setup logic when the app is launched with the `--xcodebuild-nvim-snapshot` argument. All setup methods gate their snapshot logic on this flag, making API calls a no-op in normal runs. ```swift import XcodebuildNvimPreview func applicationDidFinishLaunching() { setupUI() if XcodebuildNvimPreview.isInPreview { // Only executed when launched by xcodebuild.nvim // e.g., seed mock data, skip network calls, configure stubs MockDataLayer.seed() print("Running in Neovim preview mode — snapshots enabled") } } ``` -------------------------------- ### Setup SwiftUI Preview with Hot Reload Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Use this SwiftUI View modifier to enable live UI previews in Neovim. It captures an initial snapshot and automatically refreshes on Inject hot-reloads. The modifier is a no-op when not in preview mode, making it safe for production builds. ```swift import SwiftUI import XcodebuildNvimPreview @main struct MyApp: App { var body: some Scene { WindowGroup { // MainView is the real root; HomeView is what gets previewed. // The modifier is a no-op in normal (non-preview) runs. MainView() .setupNvimPreview { HomeView() } } } } // HomeView – the view being previewed struct HomeView: View { var body: some View { VStack(spacing: 16) { Text("Hello from Neovim Preview!") .font(.title) Image(systemName: "swift") .resizable() .frame(width: 60, height: 60) } .padding() } } // When launched with --xcodebuild-nvim-snapshot, a PNG snapshot of HomeView // is written to /tmp/xcodebuild.nvim/.png and displayed in Neovim. // On each Inject hot-reload, the snapshot is automatically refreshed. ``` -------------------------------- ### XcodebuildNvimPreview.setup(view:) Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Sets up the snapshot rendering for a given NSView or UIView. This method is intended for direct view snapshots and supports Retina displays. It is guarded by the `isInPreview` flag, ensuring it only runs during a preview session. ```APIDOC ## `XcodebuildNvimPreview.setup(view:viewController:)` — AppKit snapshot trigger ### Description The AppKit variants mirror the UIKit API. `setup(view:)` accepts an `NSView` and `setup(viewController:)` accepts an `NSViewController`, forwarding to `controller.view`. Snapshots are rendered using `NSBitmapImageRep` with Retina (`backingScaleFactor`) support. ### Method `static func setup(view: NSView) static func setup(viewController: NSViewController) ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import AppKit import XcodebuildNvimPreview // Direct NSView usage: let customView = NSView(frame: .zero) XcodebuildNvimPreview.setup(view: customView) // PNG written to /tmp/xcodebuild.nvim/.png (Retina-aware) ``` ### Response #### Success Response (Void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### UIKit: XcodebuildNvimPreview.setup(view:) Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt A static method for UIKit that captures a PNG snapshot of a given UIView. An overload for UIViewController is also available. This is used to send view snapshots to Neovim for preview. ```APIDOC ## UIKit: XcodebuildNvimPreview.setup(view:) ### Description A static method on the `XcodebuildNvimPreview` enum (UIKit variant) that takes a `UIView` and writes its PNG snapshot when running in preview mode. A convenience overload accepting a `UIViewController` is also provided and simply forwards `controller.view`. ### Method Static method ### Endpoint N/A (SDK method) ### Parameters - **view** (UIView) - The UIView to capture a snapshot of. - **viewController** (UIViewController) - The UIViewController whose view to capture a snapshot of (convenience overload). ### Request Example ```swift import UIKit import XcodebuildNvimPreview // Assuming rootVC is an instance of your root UIViewController XcodebuildNvimPreview.setup(view: rootVC.view) // Or using the convenience overload: // XcodebuildNvimPreview.setup(viewController: rootVC) ``` ### Response Writes a PNG snapshot to `/tmp/xcodebuild.nvim/.png`. No explicit return value is documented for success. ``` -------------------------------- ### SwiftUI: View.setupNvimPreview(view:) Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt A SwiftUI view modifier that registers a preview closure. It captures a snapshot when running under xcodebuild.nvim and automatically refreshes on hot reloads. It's a no-op when not in preview mode. ```APIDOC ## SwiftUI: View.setupNvimPreview(view:) ### Description A `@ViewBuilder` extension on SwiftUI's `View` protocol that registers a preview closure on the host app's root view. When running under xcodebuild.nvim, it waits 500 ms after `onAppear` to capture the first snapshot, and then automatically re-captures on every hot reload notification from Inject. When not running in preview mode the modifier is a no-op and returns `self`, so it is safe to leave in production builds. ### Method View modifier ### Usage ```swift import SwiftUI import XcodebuildNvimPreview struct ContentView: View { var body: some View { Text("Hello, World!") .padding() .setupNvimPreview { ContentView() } // Use this modifier } } ``` ### Parameters This method takes a closure that returns a `View` to be previewed. ### Response Returns `self` when not in preview mode, otherwise triggers snapshot generation. ``` -------------------------------- ### XcodebuildNvimPreview.isInPreview Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt A static boolean property that indicates whether the application is currently running in a preview mode, typically launched with the `--xcodebuild-nvim-snapshot` argument. This flag is used to conditionally execute preview-specific logic. ```APIDOC ## `XcodebuildNvimPreview.isInPreview` — Preview mode detection flag ### Description A static `Bool` property on `XcodebuildNvimPreview` that is `true` when the process was launched with the `--xcodebuild-nvim-snapshot` argument. All public setup methods gate their snapshot logic on this flag, making every API call a no-op in normal simulator or device runs. You can use this flag directly to conditionally execute any additional preview-only setup in your app. ### Method `static var isInPreview: Bool { get } ### Endpoint N/A (SDK Property) ### Parameters None ### Request Example ```swift import XcodebuildNvimPreview func applicationDidFinishLaunching() { setupUI() if XcodebuildNvimPreview.isInPreview { // Only executed when launched by xcodebuild.nvim // e.g., seed mock data, skip network calls, configure stubs MockDataLayer.seed() print("Running in Neovim preview mode — snapshots enabled") } } ``` ### Response #### Success Response (Bool) Returns `true` if the application is running in preview mode, `false` otherwise. #### Response Example N/A ``` -------------------------------- ### observeHotReload() Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Provides a Combine publisher that emits a notification whenever the Inject library performs a hot-reload. This allows for automatic re-rendering and re-snapshotting of the preview view, enhancing the development loop. ```APIDOC ## `observeHotReload()` — Combine publisher for Inject notifications ### Description A free function that returns an `AnyPublisher` wrapping a `NotificationCenter` observer for `INJECTION_BUNDLE_NOTIFICATION` — the notification posted by the [Inject](https://github.com/krzysztofzablocki/Inject) library whenever a code bundle is reloaded at runtime. Subscribing to this publisher allows the app to re-render and re-snapshot the preview view automatically on every hot-reload cycle. ### Method `func observeHotReload() -> AnyPublisher ### Endpoint N/A (SDK Method) ### Parameters None ### Request Example ```swift import XcodebuildNvimPreview import Combine class PreviewCoordinator { private var cancellables = Set() func startObservingHotReload(previewView: @escaping () -> UIView) { observeHotReload() .receive(on: DispatchQueue.main) .sink { // Re-create and snapshot the view on each injection XcodebuildNvimPreview.setup(view: previewView()) print("Snapshot refreshed after hot reload") } .store(in: &cancellables) } } // Usage let coordinator = PreviewCoordinator() coordinator.startObservingHotReload { MyFeatureView() } ``` ### Response #### Success Response (AnyPublisher) Returns a publisher that emits Void on hot-reload events. #### Response Example N/A ``` -------------------------------- ### Observe Hot Reload Notifications with Combine Source: https://context7.com/wojciech-kulik/xcodebuild-nvim-preview/llms.txt Subscribing to `observeHotReload()` allows the app to re-render and re-snapshot the preview view automatically on every hot-reload cycle from the Inject library. ```swift import XcodebuildNvimPreview import Combine class PreviewCoordinator { private var cancellables = Set() func startObservingHotReload(previewView: @escaping () -> UIView) { observeHotReload() .receive(on: DispatchQueue.main) .sink { // Re-create and snapshot the view on each injection XcodebuildNvimPreview.setup(view: previewView()) print("Snapshot refreshed after hot reload") } .store(in: &cancellables) } } // Usage let coordinator = PreviewCoordinator() coordinator.startObservingHotReload { MyFeatureView() } // Each time Inject injects a new bundle, a fresh PNG snapshot // is captured and Neovim updates its inline image display. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.