macbackend/Sources/MacBackend/Model/SwiftUI/MacBackendView.swift
david-swift e989bea14e
All checks were successful
Deploy Docs / publish (push) Successful in 2m38s
Initial commit
2024-12-02 22:14:13 +01:00

39 lines
1013 B
Swift

//
// MacBackendView.swift
// MacBackend
//
// Created by david-swift on 27.11.2024.
//
import SwiftUI
/// Display a view inside a SwiftUI view which is defined in the parent `MacBackend` widget.
struct MacBackendView: NSViewRepresentable {
/// The views defined in the parent `MacBackend` widget.
@SwiftUI.Environment(\.views)
var views
/// The view's identifier.
var id: String
/// Initialize a SwiftUI view displaying a view which is defined in the parent `MacBackend` widget.
/// - Parameter id: The identifier.
init(_ id: String) {
self.id = id
}
/// Initialize the `NSView`.
/// - Parameter context: The view context.
/// - Returns: The view.
func makeNSView(context: Context) -> NSView {
views?[id]?.pointer as? NSView ?? .init()
}
/// Update the `NSView`.
/// - Parameters:
/// - nsView: The view.
/// - context: The view context.
func updateNSView(_ nsView: NSViewType, context: Context) { }
}