Angela Yu Xcode 12 Course - Part 8 (lectures 80 to 92)
OK next day and straight back on it! This Fibonacci sequence challenge is really tricky - a lot of algorithm knowledge. Anyway, going to have a go!
Start Time - 19:21
Right so looking at her introduction, I need to create a function. Let's do it!
func fibonacci(until: Int) -> ([Int]) {
}
Basic set up done. The way I'm thinking is to have it as an array. We'll see how it goes.
func fibonacci(until: Int) -> ([Int]) {
var number1 = 0
var number2 = 1
var fibArray = [number1, number2]
var newNumber = number1 + number2
fibArray.append(newNumber)
number1 = newNumber
number2 = number1
return fibArray
}
Yep I need some help!
Let's see how Angela STARTS it at least....
Right so one difference is no return but print statements...
func fibonacci(until n: Int) {
print(0)
print(1)
var number1 = 0
var number2 = 1
for i in 0...n {
let num = number1 + number2
print(num)
number1 = number2
number2 = num
}
}
fibonacci(until: 4)
I wasn't a MILLION miles away! I think the array bit confused things. Without any help at all, I got a couple of concepts right - including the two values that needed to be added, and the swapping of values. Not too bad!
Right start of a new module and another app! This is the Xylophone app... Again, best to skim through and stop at certain key points....
Tags in storyboard
Tags are massively useful. Having just one function with multiple different buttons (xylophone keys in this case) makes total sense. I need to implement this in situations which have multiple buttons for choices.
OK I am going to skip this next bit about Stack Overflow and Apple Documentation. To summarise, you can look up the solution to various problems.
*I have very successfully done this to get a timer and a working keyboard with my HowManyLetters App!
Yep so as I thought - lots of complex code which I don't need to know at this point. But good to see the process of trying out various different solutions.
Error Catching
Now this is something that is worth going over...

Right so with the above example, it means that we need to plan in for the situation where there is no file there. Errors need to be caught!
The do/catch code block is what we use.
*Paused at 20:05
Restart at 20:33
OK! So a key point here is to search the error code on a website called OSStatus.com. On there, you can then see what to do.
Key point I've found before - is to create a function separately, then add it to where the @IB is put in.
Scope - keeping a value I want to use as a global variable.
Yes now Scope is the next thing to look at!
Scope

OK this is clever....actually using inputs for the function - so basically a global variable is not needed. Makes the code simpler.

Finish Time - 20:46 (total time: 57 minutes)
Right so some useful recap there. Bits about tags, the logic for fibonacci, error catching, functions and use of parameters/inputs instead of global variables, where to search for help online with errors or how to code something. Next time, it will be the Quizzler project, which I have done my own version of very recently! So that will be skimmed through!
Error Catching
Now this is something that is worth going over...

Right so with the above example, it means that we need to plan in for the situation where there is no file there. Errors need to be caught!
The do/catch code block is what we use.
*Paused at 20:05
Restart at 20:33
OK! So a key point here is to search the error code on a website called OSStatus.com. On there, you can then see what to do.
Key point I've found before - is to create a function separately, then add it to where the @IB is put in.
Scope - keeping a value I want to use as a global variable.
Yes now Scope is the next thing to look at!
Scope

OK this is clever....actually using inputs for the function - so basically a global variable is not needed. Makes the code simpler.

Finish Time - 20:46 (total time: 57 minutes)
Right so some useful recap there. Bits about tags, the logic for fibonacci, error catching, functions and use of parameters/inputs instead of global variables, where to search for help online with errors or how to code something. Next time, it will be the Quizzler project, which I have done my own version of very recently! So that will be skimmed through!
Comments
Post a Comment