Day 2: #MomLife and Layout Issues

**In case you missed my other posts, I’m currently working through this tutorial from Apple, where I’m making a food tracking app.

I tried to spend a couple hours coding yesterday morning, but instead ended up with a lot of frustration, due to this:

Ok, I don’t look annoyed here. But truth be told, I was.

That’s me, sitting in front of my computer, with my daughter all up in my grill. She was having a very needy day yesterday, and it did not jive well with me trying to do something that requires my full attention, like learning Swift. So I ended up frustrated and just called it quits for the day after getting through about 1/4 of 1 page of my tutorial. I slogged through it but because of all of the distractions, I couldn’t even really tell you what I did. Toddlers and learning to code don’t mix, let me tell you!

So today was a new day, and my parents took my daughter to the Children’s Museum. Yay, uninterrupted time to code!

Today I worked with view controllers so that a user can tap a placeholder image, choose an image from their photo library, and submit it with his/her meal rating. I was also introduced to the world of gesture recognizers, in this case a tap gesture. I also created an image picker: I learned how to bring up the photo library, how to disable the camera, and how to dismiss the picker once a user chooses an image.

All of this went pretty smoothly. I followed the directions in the tutorial and got the results as expected. By the end of it, I was able to replace the default image with one I chose from my simulator’s camera roll.

The next piece of the app is to implement a custom control: a ratings control that is made up of stars, where the user can choose a star rating between 1 and 5. I’m only about halfway through this section. Every time I scroll down a bit on the tutorial it just seems to get longer and longer! The tutorial tried to explain what a view is, but I ended up googling it to get a better idea. It seems like I’m adding a new stack view so that I can place the 5 rating buttons on my storyboard.

The tutorial also had me write up some initializers, but I don’t understand what I’m doing with those, I just copied what the tutorial said. If I took the time to fully understand every single thing I typed, I’d never get through the tutorial. I know that eventually I will need to understand that concept, but for now, I’m OK with blowing past some stuff for the sake of accomplishment.

In this section, I wrote my first loop in Swift! I remember loops well from C# and they are a universal programming concept. The loop was used to create 5 star buttons (I originally started with one). So far, when I tap the star rating, I’m getting a console printout of “Button Pressed”. Further along in the tutorial we will actually assign values to the buttons and save those, but I’m not there yet.

I’ve been noticing that something is “off” with my storyboard layout, and I have a feeling it has something to do with the constraints I assigned to my labels, text inputs, and image. I remember that at one point the tutorial had me group all of them together and then they will stay together. I also added constraints on the image to make sure it’s always a square. But somewhere along the way, things started looking like a hot mess compared to the tutorial:

Tutorial on the left, my app on the right


The app still functions as the tutorial says it should, so I’m not overly worried about the layout issues for now. Somehow my “Enter Meal Name” text input got way too large and so did my “Set Default Label Text” button. I tried to manually change their heights but it only caused problems because they are grouped together and have constraints. Still more to be figured out here, for sure. I also added a default image of food, where the tutorial has a different default image (“No photo selected”). So the content of that one really isn’t a problem, just the size.

I feel that many aspects of this tutorial are over my head, and as I mentioned earlier, I’m not fully understanding what I’m typing. I think that’s just the way of learning though, sometimes you have to DO before you can fully understand down the line. Here’s to continued learning!

Leave a Reply

Your email address will not be published. Required fields are marked *