Angela Yu Xcode 12 Course - Part 18 (lectures 175 to 184)
So this time we're by the pool by RAK! Probably better in terms of wind, sand etc... I've arranged for someone to collect my laptop to replace the screen. Have also ordered a new case and an ant-glare screen cover. All of these things should help and it's worth the money. Well it's a lot of it! 1575 to repair; 200 for anti-glare screen; 50 for cover. Anyway.... Today I'm going to start the Bitcoin tracker challenge. Going to spend an hour on it - maybe more. Let's go!
Start Time - 10:27
OK, step 1 is to download the project..
STEP 1
Right, I am not going to type much here as it is pretty much following instructions. Will add anything that's a useful learning point!
OK, after putting in the currencyPicker.delegate = self (and the same for the dataSource one), errors come up because we HAVE NOT CONFORMED TO THAT PROTOCOL! That makes sense - we've put in those protocols in the view controller. So those methods need implementing.
Start Time - 10:27
OK, step 1 is to download the project..
STEP 1
Right, I am not going to type much here as it is pretty much following instructions. Will add anything that's a useful learning point!
OK, after putting in the currencyPicker.delegate = self (and the same for the dataSource one), errors come up because we HAVE NOT CONFORMED TO THAT PROTOCOL! That makes sense - we've put in those protocols in the view controller. So those methods need implementing.
Ok. Using the row number is actually pretty unintuitive. Let’s change that print statement to print the currency selected instead.
- Challenge: See if you can change the code to print the currency value selected instead of the row number.
Here is what I am now working on. At the moment I have this -
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(row)
}
Loads of pickerView functions by the way! As they're all the same name but with different parameters, presumably they all execute at once?
Anyway, I need to print instead of the row - the number, I need to print the string of the currency code...
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(currencyArray[row])
}
YEs! That worked! Used the same as the return of the previous function so not technically cheating!
STEP 2 - Make the API URL
So this will involve going on a website to get the URL code.
Well before that, I've added the bit of code. Let's see if it works!
YEs! Thisis what prints -
BRL
https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCBRL
CAD
https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCCAD
CNY
https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCCNY
STEP 3 - CocoaPods
Here are the steps needed:
Steps
- Inside Terminal, Change Directory to the folder containing the BitcoinTicker project
- Initialise a new Podfile
- Open the Podfile in Xcode
- Add the two libraries (SwiftyJSON and Alamofire)
- Make sure you uncomment the use_frameworks and target platform :ios, '9.0'
- Run pod install in Terminal
- Open the .xcworkspace file
Let's do this!
Yes it seems to be working! Had to check a couple of things online and with the Clima app but actually that's a good effort!
STEP 4 - Networking
...
I managed to get quite far! Only got unglued around steps 6 to 7. So now I am checking through the solution as the bit about parsing really boggles me.
OK, useful stuff already.
Picker views - these give a scroll through of options. This makes sense - it's great for when you want to scroll through multiple values. That would be great for multiple choice answers etc!
OK connecting the picker view is quite complex - I missed that altogether.
Right so my error may well have bee not to have saved and quitted files before the pod install etc.
OK now that seems ok!
YES! Even though I went along with the solution, I still had to figure this out and apply some logic.
Finish Time - 12:02 (1 hour 35 total!)
A key thing to remember is that this sort of project would be done over DAYS or WEEKS! I've gone along with instructions for an hour or so. So great stuff and I will look at how I could apply this to another similar project at some point! The pods, the terminal, the parsing all make MUCH more sense now! That was so much fun! And the key thing was accepting that I was not going to get that myself. It was all about learning. So the whole challenge complete! New module tomorrow!
Comments
Post a Comment