Mobile App Development 2021W Lecture 9
Video
Video from the lecture given on February 8, 2021 is now available.
Notes
Lecture 9
------------
schedule
A1 solutions
T4 via live coding
Midterm
- midterm on March 3rd, 11:35 AM
- review on March 1st
- timed, 80 min, during class time
- download PDF of midterm from cuLearn
- upload solutions to cuLearn (via an assignment) before the end of exam period
- open book/internet, open note, NO COLLABORATION
- interviews afterwards to verify you understood what you said on the midterm
- random + selected
- you may volunteer
- if there is clear evidence that you don't know enough to have given the answers
you did, then I'll be talking to the Dean
- questions on midterm are more conceptual than coding
- do you know what is going on?
- treat the midterm as practice for the final
- everything you do in this class is an opportunity to raise your grade
- midterm will all be short answer
- some more conceptual, some based on specific code examples
- any "code" in answers will be very short (at most 3 lines)
- more on reading rather than writing code
Tutorial 4 is due Feb. 21st, before midnight
Assignment 2 is due Feb 26th
- midterm is based on Assignment 1 & 2, which are based on Tutorials 1-4
- (maybe Tutorial 5, but then Tutorial 5 will reinforce concepts from 1-4)
Defensive programming
- planning for eventualities that are "impossible", because you know,
they turn out to be possible when you least expect it
- especially as code evolves over time
Code
import SwiftUI
struct ContentView: View {
@State var c = 0
@State var p = CGPoint(x: 0, y: 0)
var body: some View {
VStack{
Text("Hello, you clicked \(c) times.")
.padding()
Image("sadDog")
.resizable()
.scaledToFit()
.position(p)
.gesture(
DragGesture()
.onEnded {_ in
print("Drag ended!")
self.p = CGPoint(x: 0, y: 0)
}
.onChanged {v in
self.p = v.location
}
)
.onTapGesture(count: 1, perform: {
c = c + 1
})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}