SwiftUI

{{Short description|User interface framework}}

{{One source|date=January 2024}}

{{Infobox software

| logo = SwiftUI logo.png

| logo size = 85px

| name = 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/swiftui/

}}

SwiftUI is a declarative framework{{Cite web |last=Mayo |first=Benjamin |date=June 3, 2019 |title=Apple announces SwiftUI, a modern declarative user interface framework for Apple platforms |url=https://9to5mac.com/2019/06/03/apple-announces-swiftui-a-modern-declarative-user-interface-framework-for-apple-platforms/ |access-date=January 22, 2024 |website=9to5mac.com}} 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.{{Cite web |title=SwiftUI |url=https://docs.developer.apple.com/documentation/swiftui |access-date=2024-01-10 |website=Apple Developer Documentation |language=en-US}}

SwiftUI integrates with other Apple technologies, such as Xcode and Swift Playgrounds to provide for real-time previews during editing,{{Cite web |title=Previews in Xcode |url=https://developer.apple.com/documentation/swiftui/previews-in-xcode |access-date=2023-11-07 |website=Previews in Xcode – Apple Developer Documentation |language=en |archive-url=https://web.archive.org/web/20231107221047/https://developer.apple.com/documentation/swiftui/previews-in-xcode |archive-date=2023-11-07}}{{Cite web |title=Swift Playgrounds |url=https://developer.apple.com/swift-playgrounds/ |access-date=2024-01-31 |website=Apple Developer |language=en}} alongside support for debugging and other development features.

SwiftUI allows for interoperability with UIKit and AppKit views via the UIViewRepresentable and NSViewRepresentable protocols respectively.{{Cite web |title=Interfacing with UIKit |url=https://docs.developer.apple.com/tutorials/swiftui/interfacing-with-uikit |access-date=2024-01-31 |website=Apple Developer Documentation |language=en-US}}{{Cite web |title=AppKit integration |url=https://developer.apple.com/documentation/swiftui/appkit-integration |access-date=2024-10-06 |website=Apple Developer Documentation |language=en-US}}

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.{{Cite web |title=MapKit for SwiftUI |url=https://docs.developer.apple.com/documentation/mapkit/mapkit_for_swiftui |access-date=2024-01-10 |website=Apple Developer Documentation |language=en-US}} 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.{{Cite web |title=Canvas |url=https://docs.developer.apple.com/documentation/swiftui/canvas |access-date=2024-01-31 |website=Apple Developer Documentation |language=en-US}}

During WWDC 2022 and the iOS 16 release cycle, Apple released Swift Charts, a framework for making customizable and accessible charts.{{Cite web |title=Swift Charts |url=https://docs.developer.apple.com/documentation/charts |access-date=2024-01-31 |website=Apple Developer Documentation |language=en-US}}

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.{{Cite web |title=Meet SwiftUI for spatial computing - WWDC23 - Videos |url=https://developer.apple.com/videos/play/wwdc2023/10109/ |access-date=2024-01-31 |website=Apple Developer |language=en}}

Examples

The following is an example of a simple Hello World program. The {{code|@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 the Model–View–ViewModel (MVVM) architectural pattern.{{Cite book |last=Hudson |first=Paul |title=Swift Design Patterns |publisher=Paul Hudson |year=2018 |language=English}}{{self-published source inline|date=April 2024}}

import SwiftUI

@main

struct AnApp: App {

var body: some Scene {

WindowGroup {

ContentView()

}

}

}

struct ContentView: View {

var body: some View {

Text("Hello, World!")

}

}

References

{{Reflist}}

Further reading

  • {{Cite book |last=Lee |first=Wei-Meng |title=SwiftUI for dummies |date=2020 |publisher=Wiley |isbn=978-1-119-65270-0 |location=Hoboken}}
  • {{cite book |last=Cahill |first=Bear |date=2021 |title=UI Design for iOS App Development |url=https://link.springer.com/book/10.1007/978-1-4842-6449-2 |language=en |doi=10.1007/978-1-4842-6449-2|isbn=978-1-4842-6448-5 |s2cid=229306131 }}
  • {{Cite book |last=Barker |first=Chris |url=https://books.google.com/books?id=t1TbDwAAQBAJ |title=Learn SwiftUI: An introductory guide to creating intuitive cross-platform user interfaces using Swift 5 |date=2020-04-03 |publisher=Packt Publishing Ltd |isbn=978-1-83921-087-7 |language=en}}

{{iOS}}

Category:Gesture recognition

Category:IOS

Category:IPhone

Category:Proprietary software