Lecture 1: Intro to SwiftUI Flashcards
What is the framework/package we must import for any SwiftUI functionality to work? (Full syntax)
import SwiftUI
What is a Struct?
A data structure
In SwiftUI, what must any Struct that wants to act as a view contain?
It must declare a variable, body, which acts as a view.
What do we call a variable which is declared within a struct?
A property. It is a property of the struct it is declared within.
What is the syntax to create a Struct of type View, named ContentView in SwiftUI?
struct ContentView: View {}
What is the syntax to create the body variable (view) within this struct?
var body: some View {}
If we declare a var body of type ‘some View’, what must this variable/function return?
It must return something of type view. In SwiftUI this could be Text(“”), Image(UIImage…” etc.
What is the syntax to create our struct view, with our body var, and have it return the text “Hello, World!”?
import SwiftUI
struct ContentView: View { var body: some View { Text("Hello, World") } }