Week 3 of iOS Dev Academy

iDev
4 min readMar 18, 2020

The same question kept going through my mind, “Why?” I had to remind myself of why I’m doing this. People are depending on me. This week was a rough one, some setbacks had me feeling discouraged and that I can’t do this. I reached out to a mentor and he got me right back on track. Now, we’re moving forward.

Week 3

My pace has slowed down a lot. Some things stick, and some things take a while to fully comprehend. I’m not in a race. Sure, I would like to reach my goals quicker, but as long as I’m moving forward, there’s no shame in that.

As soon as I hit Enumerations and Switch, I noticed myself slowing down. I was still able to move on, but once I got to Optionals, I was lost. I know, if you can explain something well, then I know you understand it. It’s just common sense right? You can’t tell someone how to get to the grocery store if you don’t know the way. So here’s me explaining Enumerations.

A great use of an Enumeration is when there are multiple choices of a related group. First we can give the “enum” or “Enumeration” a name, then we declare it’s choices inside the brackets by using the word “case.”

The name of an enum starts with a capital letter, like all other type names. All the names of a case starts with a lower-case letter, like the names of properties and methods. The name of the enum should be singular, as in PizzaTopping, not PizzaToppings, because you can only choose (this is called making an instance) one at a time.

These are two examples of instances. An enum limits the choices to one of its cases. You can’t order off-menu. This is great, but when it comes to using enums in functions, it might introduce some unwanted outputs. I’ll give an example assuming you know how functions work.

The problem is you get “Sausage please” if the others aren’t selected. To remedy that, we could give that instance a return value of “ Sausage please.”

The problem is the last return string saying “Erm…how did we get here?” Because this the function has to have a return statement of type string. This is where Switch comes in.

The switch statement starts with the keyword switch, followed by the value that it’s checking and an opening bracket. Next you add a series of cases to be checked, each with the case keyword, followed by a value and a colon. My choice will have the value of “Mushroom please.” This could be utilized in a food ordering app of some sort. Now everything has a nice value and doesn’t “need” to return a String saying “Erm.”

This turned out to be more coding heavy so I hope you can take away something. If I were teaching this, it would been have broken down even more so that a child could understand. This article is just a summary of what I’ve learned and to also help me grasp it better because I’m being forced to understand it before I can explain it.

Hopefully I can explain Optionals better next week. Until next time, keep moving forward, and if you need help, ask!

Rick Martinez

--

--