Module 4 continues with Lesson 4, in which we handle user sign-in and create account, using:
Auth.auth().signIn(withEmail: email, password: password)
and:
Auth.auth().createUser(withEmail: email, password: password)
with:
ref.setData(["name":name], merge: true)
and, of course:
Auth.auth().signOut()
Lesson 5
In Lesson 5 of the module, we handle using Firestore to keep track of the last lesson / question the user was looking at so that, later, we can return them to the same place when they re-open the app.
In this lesson, another gremlin rears its head. At about 9:45 in the video, Chris notes that going through the lessons changes lastLesson
in the Firestore but, when finished, it doesn’t change back to 0. Mine does, oddly.
Chris checks out the code and discovers that a button action, when there are no more lessons, should be calling up the model.nextLesson()
method. But, again oddly, ours already does.
On looking into this, it appears another gremlin has crept into the code of our ContentDertailView.swift file
The provided ‘starter project’ for iOS Databases, Module 4 looks like this:
if model.hasNextLesson() {
Button(action: {
model.nextLesson()
}, label: {
...
})
}
else {
Button(action: {
model.currentContentSelected = nil
}, label: {
...
})
}
Our LearningApp from iOS Foundations, Module 4 looks like this:
if model.hasNextLesson() {
Button(action: {
model.nextLesson()
}, label: {
...
})
}
else {
Button(action: {
model.currentContentSelected = nil
model.nextLesson()
}, label: {
...
})
}
I don’t know how it went missing from Chris’ version of the file. There are some odd gremlins going on with this module.
That aside, one exciting element we look at in this lesson is how to have the app react when it’s being sent to the background (perhaps when the user has had enough for now and wants to do something else).
Adding the following to our main LaunchView.swift file fulfills this purpose:
struct LaunchView: View {
@EnvironmentObject var model: ContentModel
var body: some View {
if model.loggedIn == false {
...
} else {
TabView {
HomeView()
...
ProfileView()
...
}
.onAppear {
model.getDatabaseData()
}
.onReceive(NotificationCenter.default.publisher(for:
UIApplication.willResignActiveNotification)) { _ in
model.saveData(writeToDatabase: true)
}
}
}
}
I can see that being very crucial in future apps.
Lesson 6
With lesson 6, we put the finishing touches to the Learning App that allows the user to leap back into the lesson / question they were last viewing when they resume the app.
This lesson covered a lot very quickly, but it’s the end of the module so I’m printing everytihng out as usual. I think I should take out shares in a paper factory.
Chris suggests going back to earlier lessons, now that we’ve moved on so far, to refamiliarise ourselves with how things work if it’s been a bit rapid. That’s a fair assessment, but I only have a limited amount of time before my CWC+ subscription expires and I very much doubt I’ll be able to renew it when it does – which will mean I’ll lose all access to any and all courses. That’s why I’m blogging & printing after each lesson / module, so that I’ll always have something to refer back to when my access to CWC+ expires. Spending time revisiting previous lessons now will deprive me even further of time for lessons I’ve not year viewed. I must push on out of necessity…