SwiftUI Reference

What is SwiftUI

SwiftUI is a declarative UI framework that allows developers to design apps across all Apple platforms.

The Starter SwiftUI Document

import SwiftUI

struct ContentView : View {
    var body: some View {
        Text(“Hello World”)
}
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
}
}
#endif

Example Explained

Swift UI components are the foundation of the framework. 

SwiftUI Components

  • import SwiftUI – References the SwiftUI module for use in the code
  • struct ContentView : Views – Creates a new class 
  • var body: some View – Creates a subclass of View
  • Text() – Defines the Text that will be displayed
  • #if DEBUG – Specifies to the compiler what content to preview
  • struct ContentView_Previews – Initiates the preview class
  • static var previews: – Specifies the content to preview
  • ContentView() – Specifies the class that will be previewed
  • #endif – Specifies the end of the content to be previewed

Made with ❤ By Mason Dierkes

Close Menu