Angela Yu Xcode 12 Course - Part 5 (lectures 51 to 54)
After a couple of days where I literally had no time to code, I am back! Cracking on with Angela's course. As before, for these projects I am just skimming through and working out any answers to her questions as I go. Right let's start!
Start Time - 20:41
Arrays in Swift
Image View - think of these as a picture frame. Something will go inside.

So that is the code for changing the image view - using the property of image then the UIImage class.
So that will make the left die show 'dice 2'.
Of course the best way to do this would be to create a dice array.
E.g. var diceArray = ["dice1", "dice2"...]
Then have the random integer in the [] shown each time.
Arrays - no need to go over this. I know they're the same type, start from index 0 etc.

So instead of 1 in the square brackets, use the randomDiceIndex1 value. That will mean a random one each time. Same for both dice. Easy!
DRY Principle
Don't Repeat Yourself!
OK the idea here I think will be to create a function, then use this again for when the button is pressed - saves using the same code twice.

Yes as expected! This is something I'm pretty good at.
Functions - think of these as needing a VERB!
Motion Detection

So that's the end of the Dicee project. Neat!
Finish Time - 20:59 (total time 18 minutes)
Probably the shortest entry I've ever done! But good just to keep my eye in and this ticking over. A lot was skimmed through, so more was covered than you would think. Anyway, a couple of concepts clarified - use of function, which I've been doing and the randomisation. Use of the image property and using UI to specify - I'm sure that will come in handy. Next time it is the 8 ball challenge. So I'm going to try to do that without any help at all - should be easy enough!
Start Time - 20:41
Arrays in Swift
Image View - think of these as a picture frame. Something will go inside.

So that is the code for changing the image view - using the property of image then the UIImage class.
So that will make the left die show 'dice 2'.
Of course the best way to do this would be to create a dice array.
E.g. var diceArray = ["dice1", "dice2"...]
Then have the random integer in the [] shown each time.
Arrays - no need to go over this. I know they're the same type, start from index 0 etc.

So instead of 1 in the square brackets, use the randomDiceIndex1 value. That will mean a random one each time. Same for both dice. Easy!
DRY Principle
Don't Repeat Yourself!
OK the idea here I think will be to create a function, then use this again for when the button is pressed - saves using the same code twice.

Yes as expected! This is something I'm pretty good at.
Functions - think of these as needing a VERB!
Motion Detection

So that's the end of the Dicee project. Neat!
Finish Time - 20:59 (total time 18 minutes)
Probably the shortest entry I've ever done! But good just to keep my eye in and this ticking over. A lot was skimmed through, so more was covered than you would think. Anyway, a couple of concepts clarified - use of function, which I've been doing and the randomisation. Use of the image property and using UI to specify - I'm sure that will come in handy. Next time it is the 8 ball challenge. So I'm going to try to do that without any help at all - should be easy enough!
Comments
Post a Comment