Ray Wenderlich Course - SwiftUI (Part 1)
OK! After the failure of developing the HowManyLetters App, I'm coming back to learning about SwiftUI. Just half an hour to get this started!
Start Time - 20:06
Key advice is to be well-versed in UIKit and SwiftUI. So that's a good point - not just going with SwiftUI and abandoning all before it!
What is SwiftUI?
According to Apple - the shortest path to a great app. You do need UI components- buttons, sliders, images etc.
Declarative -

This is different to the use of constraints etc.
Programmatic UI - use of NSlayoutconstraints, anchors etc.
So with SwiftUI, it is a new, easier to use approach.
One of the best things is the canvas view. It shouldn't matter the type of device - should work straight out of the box.
So lots of changes to Swift!
The View Protocol
ViewController - the whole point was having data and view as separate entities.
SwiftUI is DECLARATIVE! So the view is now updated automatically. No more ViewController!!
The ContentView is now a struct - a value type. It conforms to the View protocol.

So the some keyword....
The body property is an associated type. So the some keyword returns an opaque type. All that seems like techno jargon.
The Stacks -

So according to the documentation, it returns the opaque type of view. Lots of possibilities basically. Not merging with XML...
So how will this impact me? To be seen!
Laurie (the instructor) has suddenly done this -
Never seen the List thing before. The ForEach is new for SwiftUI.

That is cool - a list automatically formatted without all of the nonsense!
Start Time - 20:06
Key advice is to be well-versed in UIKit and SwiftUI. So that's a good point - not just going with SwiftUI and abandoning all before it!
What is SwiftUI?
According to Apple - the shortest path to a great app. You do need UI components- buttons, sliders, images etc.
Declarative -

This is different to the use of constraints etc.
Programmatic UI - use of NSlayoutconstraints, anchors etc.
So with SwiftUI, it is a new, easier to use approach.
One of the best things is the canvas view. It shouldn't matter the type of device - should work straight out of the box.
So lots of changes to Swift!
The View Protocol
ViewController - the whole point was having data and view as separate entities.
SwiftUI is DECLARATIVE! So the view is now updated automatically. No more ViewController!!
The ContentView is now a struct - a value type. It conforms to the View protocol.

So the some keyword....
The body property is an associated type. So the some keyword returns an opaque type. All that seems like techno jargon.
The Stacks -

So according to the documentation, it returns the opaque type of view. Lots of possibilities basically. Not merging with XML...
So how will this impact me? To be seen!
Laurie (the instructor) has suddenly done this -
let pets = ["George", "Jess", "Daisy", "Susie"]
var body: some View {
List {
ForEach(pets, id: \.self) {
Text($0)
}
}
}
Never seen the List thing before. The ForEach is new for SwiftUI.

That is cool - a list automatically formatted without all of the nonsense!
let pets = ["George", "Jess", "Daisy", "Susie"]
var body: some View {
ScrollView {
HStack {
ForEach(pets, id: \.self) {
Text($0)
}
}
}
}
Live Update, Modifiers...
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Right so this code above... This is to do with the automatic preview that is generated on the canvas.
Changing colour and other elements in the 'show UI inspector'. The code is automatically generated.
That is called the MODIFIER!
Order of modifiers is important.
Here are a whole chain of modifiers for a longish text1
Again, order is important. If we put padding after the last two, then it would not look right (I've got different text and properties of course) -
With padding back in front of the background and border again
Finish Time - 20:45 (39 minutes total)
A good start! More technical stuff but interesting diving in deep and finding out what is going on under the hood. More over the weekend!
Comments
Post a Comment