Structures
The following structures are available globally.
-
The
NSInterfaceView
struct helps you to use AppKit NSView or its derived class in project using SwiftUI.NSInterfaceView
is a type that represents part of your app’s user interface using AppKit and provides modifiers that you use to configure views.You create custom views by declaring types that conform to the
View
protocol. Implement the requiredView/body-swift.property
computed property to provide the content for your custom view. Then you can present your AppKitt View by usingNSInterfaceView(MyView())
, as follows.struct MyView: View { var body: some View { NSInterfaceView(MyView()) } }
The
View
protocol provides a large set of modifiers, defined as protocol methods with default implementations, that you use to position and configure views in the layout of your app. Modifiers typically work by wrapping the view instance on which you call them in another view with the specified characteristics. For example, adding theView/opacity(_:)
modifier to a interface view returns a new view with some amount of transparency:NSInterfaceView(MyView()) .opacity(0.5) // Display partially transparent interface view.
It is recommended to use
ZStack
withNSInterfaceView
, as follows.ZStack { NSInterfaceView(MyView()) MySwiftUIView() }
A wrapper that you use to integrate an AppKit view into your SwiftUI view hierarchy.
Use an
NSInterfaceView
instance to create and manage an doc://com.apple.documentation/documentation/AppKit/NSView object in your SwiftUI interface. Adopt this protocol in one of your app’s custom instances, and use its methods to create, update, and tear down your view. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your view with your app’s current state information. Use the teardown process to remove your view cleanly from your SwiftUI. For example, you might use the teardown process to notify other objects that the view is disappearing.To add your view into your SwiftUI interface, create your
NSInterfaceView
instance and add it to your SwiftUI interface. The system calls the methods of your representable instance at appropriate times to create and update the view. The following example shows the inclusion of aNSInterfaceView
in the view hierarchy.struct ContentView: View { var body: some View { ZStack { Text("Global Sales") NSInterfaceView(MyNSView()) } } }
The system doesn’t automatically communicate changes occurring within your view controller to other parts of your SwiftUI interface. When you want your view controller to coordinate with other SwiftUI views, you must provide a
See moreNSViewControllerRepresentable/Coordinator
object to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your view controller to any SwiftUI views.Declaration
Swift
public struct NSInterfaceView : NSViewRepresentable
-
The
NSInterfaceViewController
struct helps you to use AppKit NSViewController or its derived class in project using SwiftUI.NSInterfaceViewController
is a type that represents part of your app’s user interface using AppKit and provides modifiers that you use to configure views.You create custom views by declaring types that conform to the
View
protocol. Implement the requiredView/body-swift.property
computed property to provide the content for your custom view. Then you can present your AppKit ViewController View by usingNSInterfaceViewController(MyViewController())
, as follows.struct MyView: View { var body: some View { NSInterfaceViewController(MyViewController()) } }
The
View
protocol provides a large set of modifiers, defined as protocol methods with default implementations, that you use to position and configure views in the layout of your app. Modifiers typically work by wrapping the view instance on which you call them in another view with the specified characteristics. For example, adding theView/opacity(_:)
modifier to a interface view returns a new view with some amount of transparency:NSInterfaceViewController(MyViewController()) .opacity(0.5) // Display partially transparent interface view.
It is recommended to use
ZStack
withNSInterfaceViewController
, as follows.ZStack { NSInterfaceViewController(MyViewController()) MySwiftUIView() }
A wrapper that you use to integrate an AppKit view controller into your SwiftUI interface.
Use an
NSViewControllerRepresentable
instance to create and manage an doc://com.apple.documentation/documentation/AppKit/NSViewController object in your SwiftUI interface. Adopt this protocol in one of your app’s custom instances, and use its methods to create, update, and tear down your view controller. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your view controller with your app’s current state information. Use the teardown process to remove your view controller cleanly from your SwiftUI. For example, you might use the teardown process to notify other objects that the view controller is disappearing.To add your view controller into your SwiftUI interface, create your
NSViewControllerRepresentable
instance and add it to your SwiftUI interface. The system calls the methods of your custom instance at appropriate times.The system doesn’t automatically communicate changes occurring within your view controller to other parts of your SwiftUI interface. When you want your view controller to coordinate with other SwiftUI views, you must provide a
See moreNSViewControllerRepresentable/Coordinator
instance to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your view controller to any SwiftUI views.Declaration
Swift
public struct NSInterfaceViewController : NSViewControllerRepresentable
-
The
InterfaceView
struct helps you to use UIKit UIView or its derived class in project using SwiftUI.InterfaceView
is a type that represents part of your app’s user interface using UIKit and provides modifiers that you use to configure views.You create custom views by declaring types that conform to the
View
protocol. Implement the requiredView/body-swift.property
computed property to provide the content for your custom view. Then you can present your UIKit View by usingInterfaceView(MyView())
, as follows.struct MyView: View { var body: some View { InterfaceView(MyView()) } }
The
View
protocol provides a large set of modifiers, defined as protocol methods with default implementations, that you use to position and configure views in the layout of your app. Modifiers typically work by wrapping the view instance on which you call them in another view with the specified characteristics. For example, adding theView/opacity(_:)
modifier to a interface view returns a new view with some amount of transparency:InterfaceView(MyView()) .opacity(0.5) // Display partially transparent interface view.
It is recommended to use
ZStack
withInterfaceView
, as follows.ZStack { InterfaceView(MyView()) MySwiftUIView() }
Use an
InterfaceView
instance to create and manage a doc://com.apple.documentation/documentation/UIKit/UIViewController object in your SwiftUI interface. Use this struct in one of your app’s custom instances, and use its methods to create, update, and tear down your view controller. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your view controller with your app’s current state information. Use the teardown process to remove your view controller cleanly from your SwiftUI. For example, you might use the teardown process to notify other objects that the view controller is disappearing.To add your view controller into your SwiftUI interface, create your
InterfaceView
instance and add it to your SwiftUI interface. The system calls the methods of your custom instance at appropriate times.The system doesn’t automatically communicate changes occurring within your view controller to other parts of your SwiftUI interface. When you want your view controller to coordinate with other SwiftUI views, you must provide a
See moreNSViewControllerRepresentable/Coordinator
instance to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your view controller to any SwiftUI views.
-
The
InterfaceViewController
struct helps you to use UIKit UIViewController or its derived class in project using SwiftUI.InterfaceViewController
is a type that represents part of your app’s user interface using UIKit and provides modifiers that you use to configure views.You create custom views by declaring types that conform to the
View
protocol. Implement the requiredView/body-swift.property
computed property to provide the content for your custom view. Then you can present your UIKit ViewController View by usingInterfaceViewController(MyViewController())
, as follows.struct MyView: View { var body: some View { InterfaceViewController(MyViewController()) } }
The
View
protocol provides a large set of modifiers, defined as protocol methods with default implementations, that you use to position and configure views in the layout of your app. Modifiers typically work by wrapping the view instance on which you call them in another view with the specified characteristics. For example, adding theView/opacity(_:)
modifier to a interface view returns a new view with some amount of transparency:InterfaceViewController(MyViewController()) .opacity(0.5) // Display partially transparent interface view.
It is recommended to use
ZStack
withInterfaceViewController
, as follows.ZStack { InterfaceViewController(MyViewController()) MySwiftUIView() }
Use an
InterfaceViewController
instance to create and manage a doc://com.apple.documentation/documentation/UIKit/UIViewController object in your SwiftUI interface. Use this struct in one of your app’s custom instances, and use its methods to create, update, and tear down your view controller. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your view controller with your app’s current state information. Use the teardown process to remove your view controller cleanly from your SwiftUI. For example, you might use the teardown process to notify other objects that the view controller is disappearing.To add your view controller into your SwiftUI interface, create your
InterfaceViewController
instance and add it to your SwiftUI interface. The system calls the methods of your custom instance at appropriate times.The system doesn’t automatically communicate changes occurring within your view controller to other parts of your SwiftUI interface. When you want your view controller to coordinate with other SwiftUI views, you must provide a
See moreNSViewControllerRepresentable/Coordinator
instance to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your view controller to any SwiftUI views.
-
The
WKInterfaceView
struct helps you to use WatchKiit WKInterfaceObject or its derived class in project using SwiftUI.WKInterfaceView
is a type that represents part of your app’s user interface using WatchKit and provides modifiers that you use to configure views.You create custom views by declaring types that conform to the
View
protocol. Implement the requiredView/body-swift.property
computed property to provide the content for your custom view. Then you can present your WatchKit WKInterfaceObject by usingWKInterfaceView(MyWKInterfaceObject())
, as follows.struct MyWKInterfaceObject: View { var body: some View { WKInterfaceView(MyWKInterfaceObject()) } }
The
View
protocol provides a large set of modifiers, defined as protocol methods with default implementations, that you use to position and configure views in the layout of your app. Modifiers typically work by wrapping the view instance on which you call them in another view with the specified characteristics. For example, adding theView/opacity(_:)
modifier to a interface view returns a new view with some amount of transparency:WKInterfaceView(MyWKInterfaceObject()) .opacity(0.5) // Display partially transparent interface view.
It is recommended to use
ZStack
withWKInterfaceView
, as follows.ZStack { WKInterfaceView(MyWKInterfaceObject()) MySwiftUIView() }
A view that represents a WatchKit interface object.
Use a
WKInterfaceObjectRepresentable
instance to create and manage a doc://com.apple.documentation/documentation/WatchKit/WKInterfaceObject in your SwiftUI interface. Adopt this protocol in one of your app’s custom instances, and use its methods to create, update, and tear down your interface object. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your interface object with your app’s current state information. Use the teardown process to remove your interface object cleanly from your SwiftUI. For example, you might use the teardown process to notify other parts of your app that the interface object is disappearing.To add your interface object into your SwiftUI interface, create your
UIViewRepresentable
instance and add it to your SwiftUI interface. The system calls the methods of your representable instance at appropriate times to create and update the interface object.The system doesn’t automatically communicate changes occurring within your interface object to other parts of your SwiftUI interface. When you want your interface object to coordinate with other SwiftUI views, you must provide a
See moreNSViewControllerRepresentable/Coordinator
instance to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your interface object to any SwiftUI views.