This articlerelies largely or entirely on asingle source. Relevant discussion may be found on thetalk page. Please helpimprove this article byintroducing citations to additional sources. Find sources: "SwiftUI" – news ·newspapers ·books ·scholar ·JSTOR(January 2024) |
| SwiftUI | |
|---|---|
| Developer | Apple Inc. |
| Initial release | June 3, 2019 |
| Operating system | iOS,iPadOS,macOS,tvOS,watchOS,visionOS |
| Type | Software framework |
| License | Proprietary |
| Website | https://developer.apple.com/swiftui/ |
SwiftUI is adeclarative framework[1] for buildinguser interfaces foriOS,iPadOS,watchOS,tvOS,visionOS andmacOS, developed byApple Inc. for theSwift programming language.
SwiftUI isdeclarative, contrasting with theimperative syntax used in other Apple development frameworks such asUIKit andAppKit. SwiftUI allows for 2D drawing, animations,event handling, widgets, anddata binding. SwiftUI automatically synchronizes between UI views and data.[2]
SwiftUI integrates with other Apple technologies, such asXcode andSwift Playgrounds to provide for real-time previews during editing,[3][4] alongside support for debugging and other development features.
SwiftUI allows for interoperability with UIKit and AppKit views via theUIViewRepresentable andNSViewRepresentable protocols respectively.[5][6]
SwiftUI was announced at the company'sWorldwide Developers Conference (WWDC) on June 3, 2019, and was added iniOS 13 andmacOS Catalina.[1]
During WWDC 2020 and theiOS 14 release cycle, Apple natively added support for maps with theMap view, with an interface based onApple Maps via MapKit.[7] MapKit allows for map annotation and satellite imagery.
During WWDC 2021 and theiOS 15 release cycle, Apple added theCanvas element, adding support forImmediate mode drawing and performant 2D drawing.[8]
During WWDC 2022 and theiOS 16 release cycle, Apple released Swift Charts, a framework for making customizable and accessible charts.[9]
During WWDC 2023, Apple announced theApple Vision Pro, and support for the device was added to SwiftUI, alongside new views for AR content such asRealityView andImmersiveSpace.[10]
The following is an example of a simpleHello World program. The@main attribute defines the entry point into the app. It is standard practice in SwiftUI to separate the application struct and views into different structs, according to theModel–View–ViewModel (MVVM) architectural pattern.[11][self-published source?]
importSwiftUI@mainstructAnApp:App{varbody:someScene{WindowGroup{ContentView()}}}structContentView:View{varbody:someView{Text("Hello, World!")}}