Angela Yu Course Part 2 (up to lesson 43!)
So this is the only chance I'll get probably for a bit of coding today! When reading about Angela's top 12 tips for coding, she mentioned plenty of useful tidbits. One was to WANT to do it - and I certainly do! If you do it enough days it does become a necessity! Realistically, there will be days when that will be difficult e.g. this weekend I'm staying with friends in Basingstoke. However, I can still do a bit on the train, or just more the following day. Anyway, she had some other useful advice, which I'll summarise at some point. Her point was to tell your brain that you'll do 'just 20 minutes' - then if you go over, it's no big deal! Whereas if you say that you'll do e.g. an hour, that can seem intimidating. So I'm going to do something in between that - no more than an hour anyway for now!
Dicee App
Great! Another hands on practical sounds ideal - more useful than going through endless playground examples! She does a lot of 'if you haven't done that lesson, you should go back and do so...of course I have! This tutorial will cover coding - collections (arrays), linking design to code, IB outlets and actions, randomisation and core pieces that make up an app.
So far, we've added an image views, got all of the assets with the icons and key images needed. Then I've changed the background to the image she's given. Neat!
Challenge - add in the diceelogo - done! Changed to Aspect Fit too. All that is fine now. Thanks Angela! So all design is done:

Linking Design With Code
So this is all about linking objects to the actual code. This is all familiar.
Document outline - little button in middle bottom left to bring up list of files
Utilities pane - right hand side
Good to know about the options for touching the button - touch up inside is all I've needed so far - which Angela confirms you will generally use. Curly braces - a block of code: needed for the action (button) but not for the outlet (labels). Button gives you the option for outlet or for action - you can change both appearance and have for actions. Image views (the dice pictures) only have outlet options. Makes total sense!
Debugging
OK, I hope this isn't Error Handling - my nemesis! No, I think the difference is debugging is fixing errors, whereas error handling is anticipating issues the user will face and having options to deal with them. Angela shows the 'SIGABRT' - an error I have noticed a few times! So changing the label names or not having an object connected will cause this. So you have to break the connections (double click and delete any connections on the list). If the black little circle is not filled, then you know it is not matched up. That is logical and makes perfect sense.
How to Create Randomisation in Swift
So now we are going to start coding!
OK, the switch statement was my idea! May not be the most efficient way of doing so, we'll see what Angela says....
It would be better to have these as enums surely?
I knew it would be easier! You don't need the whole named and string bit...
Dicee App
Great! Another hands on practical sounds ideal - more useful than going through endless playground examples! She does a lot of 'if you haven't done that lesson, you should go back and do so...of course I have! This tutorial will cover coding - collections (arrays), linking design to code, IB outlets and actions, randomisation and core pieces that make up an app.
So far, we've added an image views, got all of the assets with the icons and key images needed. Then I've changed the background to the image she's given. Neat!
Challenge - add in the diceelogo - done! Changed to Aspect Fit too. All that is fine now. Thanks Angela! So all design is done:
Linking Design With Code
So this is all about linking objects to the actual code. This is all familiar.
Document outline - little button in middle bottom left to bring up list of files
Utilities pane - right hand side
Good to know about the options for touching the button - touch up inside is all I've needed so far - which Angela confirms you will generally use. Curly braces - a block of code: needed for the action (button) but not for the outlet (labels). Button gives you the option for outlet or for action - you can change both appearance and have for actions. Image views (the dice pictures) only have outlet options. Makes total sense!
Debugging
OK, I hope this isn't Error Handling - my nemesis! No, I think the difference is debugging is fixing errors, whereas error handling is anticipating issues the user will face and having options to deal with them. Angela shows the 'SIGABRT' - an error I have noticed a few times! So changing the label names or not having an object connected will cause this. So you have to break the connections (double click and delete any connections on the list). If the black little circle is not filled, then you know it is not matched up. That is logical and makes perfect sense.
How to Create Randomisation in Swift
So now we are going to start coding!
randomDiceIndex1 = Int(arc4random_uniform(6))
randomDiceIndex2 = Int(arc4random_uniform(6))
Obviously had to create variables first. This looks like a very simple way for generating random numbers for dice! Now the next step will be to match up pictures of the dice to reflect the changes in the dice!
Data Types, Constants and Variables
This will probably seem very familiar so am just going to skim over this one. camelCase reminders.
Yep all of this very familiar - no need to go over.
https://www.udemy.com/ios-11-app-development-bootcamp/learn/v4/t/lecture/7555788?start=0
This link is about the maximum number of apps used....might be useful if this happens to me at some point!
diceImageViewOne.image = UIImage(named: "dice1")
switch randomDiceIndex1 {
case 0: diceImageViewOne.image = UIImage(named: "dice1")
case 1: diceImageViewOne.image = UIImage(named: "dice2")
case 2: diceImageViewOne.image = UIImage(named: "dice3")
case 3: diceImageViewOne.image = UIImage(named: "dice4")
case 4: diceImageViewOne.image = UIImage(named: "dice5")
case 5: diceImageViewOne.image = UIImage(named: "dice6")
default: diceImageViewOne.image = UIImage(named: "dice6")
}
}
OK, the switch statement was my idea! May not be the most efficient way of doing so, we'll see what Angela says....
It would be better to have these as enums surely?
I knew it would be easier! You don't need the whole named and string bit...
OK, you win Angela - your way is more elegant!
let diceArray = ["dice 1", "dice 2", "dice 3", "dice 4", "dice 5", "dice 6"]
diceImageViewTwo.image = UIImage(named: diceArray[randomDiceIndex2])
However, I'm keeping both in, just so that I have both types of codes in :)
Ok what is going on...Angela's code makes the dice disappear! When I put them both with her code they both disappear! There must be something to add here....
Well, a bit off a cliffhanger - but what great practice! Obviously I will find out what happens to the dice and why they disappear but it was great to see more code in practice and have my own go first!
Very nice blog,keep sharing more posts with us.
ReplyDeleteThank you...
swift course