Angela Yu Xcode 12 Course - Part 13 (lectures 157 to 163)
How unusual, an entry on Tuesday afternoon?! Well, mercifully, there is time off work in Dubai due to the Pope's visit! Not that I am seeing the man himself but thank you! Yesterday was also off but no chance to code. So today I have a good hour or so to get some done. My aim is to totally finish the 'Clima' app, then I will have surpassed my progress from last time. It's been a good month or so with Angela and I am 100% happy with that. Loads of useful things picked up along the way, whether the content is new or I had just forgotten bits. Either way, well worth it. The other good news is that I feel NO inclination to switch courses whatsoever. No, I want to stick with this one from Angela until the very end. Then I will review where I am and what the next course of action is. Anyway, let's go!
Start Time - 14:04
Asynchronous method - this means it works in the BACKGROUND as a method. If it were in the foreground, it means that it would freeze up the entire app and this would be shown until it's done. It would make the app appear to be crashed.
So methods are being put in for retrieving location and what happens if that fails e.g. when user has no connectivity.
Start Time - 14:04
Asynchronous method - this means it works in the BACKGROUND as a method. If it were in the foreground, it means that it would freeze up the entire app and this would be shown until it's done. It would make the app appear to be crashed.
So methods are being put in for retrieving location and what happens if that fails e.g. when user has no connectivity.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
}
So with this an array of the locations is used. When location manager is asked to get current location, each time it gets a new value, it adds it to that array. We're only interested in the most ACCURATE location. So the LAST value is the one we want as it starts off more general and gets more specific as it goes along.
A graph to show the accuracy.
OK so on Debug, I've set location to be Apple and that shows that it shows the longitude and latitude.
So now we need to turn coordinates into parameters....
OK this is challenging stuff but I'm trying my best to soak it all in!
Delegation
So I asked about this before. Let's try to make sense of it!!
Delegation pattern is like the core location manager volunteering for the job of finding the location and reporting it back. All of that code has been created already by Apple. The delegate is like the messenger....
So the CoreLocation protocol is the delegate. If the delegate is nil, then nothing happens with the info. If the delegate is set, then the CoreLocation info will get sent to the ViewController.
I sort of get that - hopefully it will come more with time! We CAN'T see how Apple actually sends out the delegate but we can with our own delegates, when we make them!
So to use the LocationManager we need to set a delegate. Setting a class that deals with location, when the location manager finds it.
Dictionary stuff - all fine.
APIs
OK more about these!
Application Programme Interfaces. I get this - you make a request to the website with the rules of the API, then you retrieve that data - the website returns a response. In our case, it is weather data.
Advantages of APIs - they are more robust.
Alamofire - this module has now been imported at the start.
Parameters - INPUTs. Think of them that way!
HTTP methods for request - we're going for .get but there are alternative ones
func getWeatherData(url: String, parameters: [String: String]) {
Alamofire.request(url, method: .get, parameters: parameters).responseJSON {
response in
if response.result.isSuccess {
} else {
}
This is a good example of something -
print("Error: \(response.result.error)")
self.cityLabel.text = "Network Issues"
The print line is for the code - to debug what the issue is. The self.cityLabel line is for the user - all they need to know is that there are Network Issues!
Better still with optional binding -
} else {
if let theError = response.result.error {
print("Error \(theError)")
}
self.cityLabel.text = "Connection Issues"
}
Networking
This is communication between computers on a network.
Different types of requests - get, post and delete.
JSON
Going to find out more about this!
Right so some stuff about casting and forced unwrapping.
let weatherJSON: JSON = JSON(response.result.value!)
Same issue as before - none of the JSON stuff seems to be working! Going to plough on anyway....
Right so I've gone back painstakingly and fixed a couple of things. Some of it is working now!
OK that will do there - spent so long on this today!
Finish Time - 15:54 (1 hour 50 minutes)
So obviously that wasn't ALL successful! In fact that was pretty painful today but it's all good! I'm learning and soaking up one element at a time. The next goal will be to complete the Clima app, even if it doesn't work! I've got something wrong at some point, or the updated Xcode just won't work. Either way, it's the PROCESS that I'm learning about and absorbing as much as I can. One thing at a time.
Comments
Post a Comment