SwiftUI: Difference between revisions

Content deleted Content added
Copyvio revdel completed (RR)
and I got the wrong link, so much for double checking. See previous edit summary.
 
(4 intermediate revisions by 4 users not shown)
Line 10:
| genre = [[Software framework]]
| license = [[proprietary software|Proprietary]]
| website = https://developer.apple.com/xcode/swiftui/
}}
 
Line 20:
SwiftUI integrates with other Apple technologies, such as [[Xcode]] and [[Swift Playgrounds]] to provide for real-time previews during editing,<ref name=":0">{{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}}</ref><ref>{{Cite web |title=Swift Playgrounds |url=https://developer.apple.com/swift-playgrounds/ |access-date=2024-01-31 |website=Apple Developer |language=en}}</ref> alongside support for debugging and other development features.
 
SwiftUI allows for interoperability with UIKit and AppKit views via the <code>UIViewRepresentable</code> structand <code>NSViewRepresentable</code> protocols respectively.<ref>{{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}}</ref><ref>{{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}}</ref>
 
== History ==
Line 34:
 
== Examples ==
The following is an example of a simple [["Hello, World!" program|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|Model–View–ViewModel]] (MVVM) architectural pattern.<ref>{{Cite book |last=Hudson |first=Paul |title=Swift Design Patterns |publisher=Paul Hudson |year=2018 |language=English}}</ref>{{self-published source inline|date=April 2024}}
<syntaxhighlight lang="swift">
import SwiftUI
Line 46:
}
}
 
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
</syntaxhighlight>