Building a Vending Machine App - Part 5 (final!)

OK, not long after the last blog! This will be the final part for this course - as I've mentioned before, I'm looking forward to completing this one now. 

Adding User Interaction

Buttons/Actions - represented by the UIAction class. The alert (for our error messages) is a certain UIAlertAction...

*I'm learning that there are so many inbuilt classes, which relate to specific objects...


An action is an instance of UIAlertAction in this case...

The parameters give you the information to fill in. Makes sense.

So instead of clicking and dragging the button etc, you can type it out in code...

Functions are 'first class' types. A lot of this is very complex so I'm not going over it in great detail to be honest. Basically for each error, we need an alert with then a button to dismiss the alert.

Comparing Answers

So in the 'catch' statements, you can display a specific string message, which refers to the value needed/not needed. Not much else to say here.

Displaying Custom Views Modally

OK so you can design a view completely in code - but not yet! Creating a new view controller - like adding a button then changing the colours etc. So the new view is the custom modal view, not programming in code. You use a modal when interrupting the current set of actions before moving back to the main steps. 'Thoughtful' animation would be even better but we're not ready for that yet either!

Controlling Custom Views

This is basically to get the 'dismiss' button to work.

*Key lesson - when making an error in linking an object to code, right click and remove all links you do NOT want! I've had that before... SIGABRT error!

Recap

Pasan makes a good point about being overwhelmed from the tricky elements.
Advice - don't worry about it because you will learn more! Going away and trying to learn about it is a good idea but to be honest, I can't see myself spending time on that just yet, until I've had some more experience.

It has been useful to see so many aspects in actions -

Protocols - modelling behaviour from the get-go. Defining the interface.

Enums - providing options which were built-in, rather than typed in as strings. Safer code. Using a series of custom types. Using an instance method - returning the right icon - better than adding strings.

Temp views and modals - for the alert and for the entire screen. Both useful to find out about! There is much more scope of course with modals....


Three main takeaways -


  • Use protocols to define flexible objects
  • Always right good error handling code
  • Always inform user of what went wrong!

So that's it! The end of the course. Phew! I won't lie - it's seemed quite futile at times, but taking out those takeaways that Pasan has explained makes me realise that it was not all pointless. It's great to get on so much hands-on experience with it, bridging the gap between the Swift language and the Xcode program more and more. I have a couple more courses, or 'workshops' from Pasan, before I tackle the courses I have purchased on Udemy. More later!









Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)