SwiftUI explained

Logo Size:85px
SwiftUI
Developer:Apple Inc.
Released:June 3, 2019
Operating System:iOS, iPadOS, macOS, tvOS, watchOS, visionOS
Genre:Software framework
License:Proprietary
Website:https://developer.apple.com/xcode/swiftui/

SwiftUI is a declarative framework[1] for building user interfaces for iOS, iPadOS, watchOS, tvOS, visionOS and macOS, developed by Apple Inc. for the Swift programming language.

Overview

SwiftUI is declarative, contrasting with the imperative syntax used in other Apple development frameworks such as UIKit and AppKit. SwiftUI allows for 2D drawing, animations, event handling, widgets, and data binding. SwiftUI automatically synchronizes between UI views and data.[2]

SwiftUI integrates with other Apple technologies, such as Xcode and Swift 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 views via the UIViewRepresentable struct.[5]

History

SwiftUI was announced at the company's Worldwide Developers Conference (WWDC) on June 3, 2019, and was added in iOS 13 and macOS Catalina.

During WWDC 2020 and the iOS 14 release cycle, Apple natively added support for maps with the Map view, with an interface based on Apple Maps via MapKit.[6] MapKit allows for map annotation and satellite imagery.

During WWDC 2021 and the iOS 15 release cycle, Apple added the Canvas element, adding support for Immediate mode drawing and performant 2D drawing.[7]

During WWDC 2022 and the iOS 16 release cycle, Apple released Swift Charts, a framework for making customizable and accessible charts.[8]

During WWDC 2023, Apple announced the Apple Vision Pro, and support for the device was added to SwiftUI, alongside new views for AR content such as RealityView and ImmersiveSpace.[9]

Examples

The following is an example of a simple Hello World program. It is standard practice in SwiftUI to separate the application struct and views into different structs, according to the Model–View–ViewModel (MVVM) architectural pattern.[10] import SwiftUI

@mainstruct AnApp: App struct ContentView: View

External links

Further reading

Notes and References

  1. Web site: Mayo . Benjamin . June 3, 2019 . Apple announces SwiftUI, a modern declarative user interface framework for Apple platforms . January 22, 2024 . 9to5mac.com.
  2. Web site: SwiftUI . 2024-01-10 . Apple Developer Documentation . en-US.
  3. Web site: Previews in Xcode . 2023-11-07 . Previews in Xcode – Apple Developer Documentation . en . https://web.archive.org/web/20231107221047/https://developer.apple.com/documentation/swiftui/previews-in-xcode . 2023-11-07.
  4. Web site: Swift Playgrounds . 2024-01-31 . Apple Developer . en.
  5. Web site: Interfacing with UIKit . 2024-01-31 . Apple Developer Documentation . en-US.
  6. Web site: MapKit for SwiftUI . 2024-01-10 . Apple Developer Documentation . en-US.
  7. Web site: Canvas . 2024-01-31 . Apple Developer Documentation . en-US.
  8. Web site: Swift Charts . 2024-01-31 . Apple Developer Documentation . en-US.
  9. Web site: Meet SwiftUI for spatial computing - WWDC23 - Videos . 2024-01-31 . Apple Developer . en.
  10. Book: Hudson, Paul . Swift Design Patterns . Paul Hudson . 2018 . English.