You can develop apps to iOS, watchOS, etc. but inside them you have templates that are just starting points for certain type of apps.
Language: Swift
User Interface: SwiftUI (Storyboard is the same as UIKit)
- SwiftUI is a new thing and most of the old tutorials talk about UIKit
ContentView.swift
- By pressing
resumeyou can see what the code looks like in a device. This updates automatically when the code is changed. -
ContectView_Previewsis not something that's changed often and can be "hide" by adding a lot of line breaks. It just shows the View in the preview and can be deleted without getting any errors. SwiftUIis imported every time there is something happening in the UI andfoundationis imported when we do something else because it contains things like arrays, dictionaries, etc.structin Swift is more powerful than in some other languages because instead of just storing variables it can contain functions and behaviors.struct ContectView: Viewmeans thatContectViewbehaves/functions likeViewContentViewis the whole app background area of the device.var(variable) insidestructis called property.-
var body: some Viewwheresome Viewis type.-
somekeyword means that it can be any type as long as it behaves likeView
-
Viewreturns one view butViewContainerreturns multiple.One line function doesn't need
returnkeyword.-
some Viewcould beTextin this example-
some Viewis better format because then compiler makes the decision and often the return type changes which would also require changing this if not usingsome View
-
-
It's normal to use labels when giving parameters to functions
-
return RoudedRectangle(cornerRadius: 10.0)
-
struct ContentView: View {
var body: some View {
return ZStack(content: {
RoundedRectangle(cornerRadius: 10.0).stroke().foregroundColor(Color.orange)
Text("ghost")
})
}
}
- Some people put
.something(called View Function) to new line to stand out from other code more easily
struct ContentView: View {
var body: some View {
return ForEach(0..<4, content: { index in
ZStack(content: {
RoundedRectangle(cornerRadius: 10.0).fill(Color.white)
RoundedRectangle(cornerRadius: 10.0).stroke(lineWidth: 3)
Text("ghost")
})
})
.padding()
.foregroundColor(Color.orange)
.font(Font.largeTitle)
}
}
-
0..<4is same as[0,1,2,3] - Two
RoundedRectanglebecause the other is border and other is the background. ForEachis not Layout View the same wayZStackand that is why it should be inside a Layout View.-
If the last argument of a function is curly brace function it can be written
abc(first: 1) {stuff}after the function call.- If no other arguments
()can be removed too.
- If no other arguments
Top comments (0)