How to extend my exist Toggle with intents

I create a toggle component based on Toggle

public struct Checkbox: View {
    ...    
    public init(...) {
        ...
    }
    
    public var body: some View {
        return HStack(spacing: 8) {
            ZStack {
                Toggle("", isOn: $isPrivateOn)
                ...
            }
            ...
        }
    }
}

how can I create a init method to support init with AppIntent like:

// Available when SwiftUI is imported with AppIntents
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
extension Toggle {

    /// Creates a toggle performing an `AppIntent`.
    ///
    /// - Parameters:
    ///   - isOn: Whether the toggle is on or off.
    ///   - intent: The `AppIntent` to be performed.
    ///   - label: A view that describes the purpose of the toggle.
    public init<I>(isOn: Bool, intent: I, @ViewBuilder label: () -> Label) where I : AppIntent
}
Answered by DTS Engineer in 797217022

@zkhCreator Give this a try:

public struct Checkbox<Intent: AppIntent, Content: View>: View {
    private let intent: Intent?
    @Binding private var isOn: Bool
    @ViewBuilder private var label: () -> Content
    
    public init(intent: Intent? = nil, isOn: Binding<Bool>, @ViewBuilder label: @escaping () -> Content) {
          self.intent = intent
          self._isOn = isOn
          self.label = label
    }
 
    public var body: some View {
        HStack(spacing: 8) {
            Group {
                if let intent = intent {
                    Toggle(isOn: isOn, intent: intent, label: label)
                } else {
                    Toggle(isOn: $isOn, label: label)
                }
            }
        }
    }
}

@zkhCreator Give this a try:

public struct Checkbox<Intent: AppIntent, Content: View>: View {
    private let intent: Intent?
    @Binding private var isOn: Bool
    @ViewBuilder private var label: () -> Content
    
    public init(intent: Intent? = nil, isOn: Binding<Bool>, @ViewBuilder label: @escaping () -> Content) {
          self.intent = intent
          self._isOn = isOn
          self.label = label
    }
 
    public var body: some View {
        HStack(spacing: 8) {
            Group {
                if let intent = intent {
                    Toggle(isOn: isOn, intent: intent, label: label)
                } else {
                    Toggle(isOn: $isOn, label: label)
                }
            }
        }
    }
}
How to extend my exist Toggle with intents
 
 
Q