A No Good Very Bad Coding Day

I sat down today to code for about an hour. It’s one of the last days that we will have childcare, so I had to make the most of it before we hit the road again. Do you ever have a day where nothing works the way you expect it to? That’s what happened to me today. Almost like, I wish I would have never even sat down at my laptop today and attempted this, because I think I messed up more than I solved!

I dove back into my tutorial. I thought I remembered exactly where I was, but after about 20 minutes, the tutorial told me to take an action on a button that I hadn’t even created yet. Hmmm…I think I may have remembered incorrectly. So I combed back through the tutorial and figured out exactly where I left off.

The goal of today was to actually save my meals and display them in a list. Up until today, I have been working with hard-coded values behind the scenes. It was time to take the user’s input, store it in a “Meal” object, then pass it to the¬†MealTableViewController to display it in the list.

The tutorial had me to an unwind segue, which lets you return to view controllers that already exist. So we need the unwind segue for when the user either saves the meal object, or cancels out of the “Add” process.

I keep getting errors and using the auto-correct feature that’s built into Xcode, and I think that’s been a bad idea. It’s adding code that I don’t know about, then I get even more errors. It feels like this is getting out of hand. I’ve basically accomplished nothing today. I know this is a learning opportunity, but it sucks.

I’ve tried to back out of my changes, but I’m confused where I even left off. I got desperate enough to just open the final source code of the tutorial and compare it to what I have, which is not the way I like to learn…but I think I’ve gotten myself into a hole too deep to dig out of.

Now I have to go pick up my daughter, so this problem will have to wait for another day. To calm my nerves I leave you with a picture of one of my favorite places: Arizona.

More soon.

Fixing Build Errors and Creating Navigation

I’ve got 99 problems…

Days like this really frustrate me, but I know that they’re a part of learning. Today I spent all of my coding time fixing errors.

Last time when I finished up my tutorial section, I had a build error: “use of undeclared type”. I banged my head against the wall for about 20 minutes trying to figure out how to solve this last time I sat down…but, I know by now that as much as I want to sit there and figure it out…I should get up and do something else, because when I come back and revisit the problem, I almost always easily solve it. That was the case this time, too. I last sat down and coded about a week ago (eek – determined to up the frequency) and couldn’t figure out how to solve the build error. I sat down today and had it fixed within 5 minutes.

Instead of going through the tutorial line by line and making sure my code matches it exactly (which is a perfectly fine way to solve a problem, but it probably wouldn’t teach me much), I try to figure the error out myself. The compiler underlined the undeclared type, which was “MealViewTableCell”, a class that I made the last time I coded. Why couldn’t it find it? I looked at this class – I made it last time I did a tutorial. Turns out that I incorrectly named this file, which should have been “MealTableViewCell” – it’s easy to see how someone could get confused, right? Even though it was a simple naming error, I’m glad I figured this out without resorting to comparing my code line by line to the tutorial.

I finally solved my build error…onto the rest of the tutorial! First I had a checkpoint: I needed to run my app and make sure my TableView is populating with the meal names and pictures that I hard-coded into the table. Just because something builds does not mean you’re out of the woods. I launched the simulator, and my table view was blank.

What the tableview should look like on the left. My app on the right. Nailed it?

Luckily I figured this one out pretty quickly by going back into the tutorial and figuring out where I may have missed a step. When you go a week in between lessons, it can be hard to remember exactly where you left off. What happened was that I forgot to point my Table View Controller to the MealTableViewController class. Once I fixed this, I was able to see my Table View Populate:

Looking more like the tutorial now…

Navigation

I worked with navigation controllers and segues to build a path through my app. I’m about halfway done with this part of the tutorial, but so far, I added a navigation controller to my app. I then changed the title property of the navigation bar and added a bar button (in “+” form) as well.

I then added a “Show” segue between my meal list and the input screen for adding a new meal. Once I saw what this did, I switched the segue type to “Present Modally”. This kind of segue does not automatically have a navigation bar, so I had to manually add one by embedding it in its own navigation controller.

This is as far as I got today, but I’m really impressed by the built in functionality of the segues in iOS. I hope that this means developing navigation in apps will be easier than I expected. Time will tell!

Writing Unit Tests & Working with Table Views

I felt like I was able to get a lot done today. The real reason for this is that my parents are watching my daughter, so while she plays at the farm and the spray park, this mom gets to learn new tricks. It’s going to be hard once we get back on the road (have you checked out my travel blog?) to have quite as much time for coding with no childcare. My husband is currently freelancing his dev skills, so we will trade off time to work.

One part of today’s tutorial felt oddly familiar to me: unit tests. I wrote a new class, which defines a “meal”. A meal has 3 properties: name, rating, and photo. So I wrote unit tests against this class, to check for error states, and also to check that the class is working as expected. I tested with a zero rating, positive rating, a rating that exceeds the maximum, a negative rating, and an empty string.

I passed parameters to the Meal class and asserted that the class either did or didn’t initialized based on if the values were valid or not. I remember writing a lot of unit tests in my last coding job (I was a C# developer) so this was a really nice refresher. Unless you are coding on a regular basis, you forget a lot of things. It has been awhile since I’ve written code, so it’s comforting when I can actually remember how to do something!

Once I got past writing the unit tests for my new class, I created another scene in my storyboard. This was exciting – up until now, my app was just one screen. I changed the entry point of the app to be the table view that I just created. This table view is going to display a list of meals, ratings, and photos. I configured a custom cell, that includes my 5-star ratings control, a photo, and label for the meal name. I unchecked the “user interaction” property on the ratings control since it’s static on this scene.

I also created my first array (woot…ok, just kidding, I’m really not that excited about it) and loaded it with sample data to display in the table view. Here I used instances of my Meal class and then loaded them into the array and passed them dummy parameters…for now.

Next up is displaying the data in the table view. That’s what I’ll work on next time I sit down to code!

BTW – how do you like this tire cover we bought for our RV?

Coding When You Can

I think I may need a new blog theme. I set this site up super quickly – prior to this, I was trying to get my personal website set up with Hugo and I spent hours doing what was supposed to be a super easy install (yes there was some learning curve with Git and the Mac command line for this Windows girl). I then ran into issues with my hosting and thought you know what, screw it. This is taking up way too much time, and I’m here to learn how to code iOS apps, not to use Hugo for my personal website. So I went with my old familiar friend WordPress, picked out a free theme in about 2 minutes, and here I am. What I was getting at here is that I hate that the blog looks like crap unless I put a picture in the post! I mean, how many selfies can I take with my computer before it’s just boring for everyone?!

Tonight I decided to get behind the keyboard for a little while, even though it’s late and it’s Sunday and I’m up against giving my daughter her bath and bedtime routine. It seems like with my schedule, I can only spend time coding every couple of days. I think the important thing is not the frequency, but just the fact that I keep coming back to it. I’m a very determined person, and I am determined to make time for this and to see it through. The wheels in my mind are already churning about what my first app is going to be. I’m going to keep it very simple at first, but I’m excited. And I’m already kind of “over” the demo app. Is that terrible to say? I just want to care about what I’m developing, and I do not care about a food tracker. I’ve never tracked food a day in my life!

However I think I’m going to complete the tutorial. I’m about halfway done, and what’s left is back end stuff – defining a data model and actually saving the food ratings and displaying them back to the user.

Today I worked on the ratings control of my demo app. I learned how to add images to the Assets folder, how to style those images, and how to use the star rating in various selection states (highlight, empty, filled, cleared) based on the user’s actions. When a user uses the ratings control, I now have the selectedRating tracking a number behind the scenes. I also learned about property observers, although I don’t really understand them yet.

So next time I work, I’ll define a data model. I’m interested to see how this works, since my prior experience is with a SQL backend. That’s it for today! I’m off to go wash dishes then give my toddler a bath…#momlife

PS – I recently ran a SEO business and the minimum ‘good’ blog post length for SEO purposes is 1,000 words. It’s giving me some kind of enjoyment to write such a short posts, knowing that I am doing this just as an outlet for myself, not to hit some kind of magical word count or keyword score. Short blogging is so much easier ūüėČ

Day 1: Jumping in with Xcode

I decided to sit down and spend a few hours starting to learn Xcode (the IDE for iOS) and Swift (the programming language for iOS apps) for day 1 of my self-taught learning experience. But where to begin? I knew a Google search would be overwhelming. Judge this however which way you want, but I wasn’t ready to lay down any cash for paid lessons or content. I started by reading the Swift documentation but before I knew it my eyes were glazed over.

My husband Tim is a developer, and he asked me a good question: why are you starting with the low level stuff? Why not start at a higher level, then learn syntax as you need to? Logical, logical Tim. But he was so right. He sent me a couple links. I started with this article on medium. It gave me a high-level lay of the land.¬†Then I started on this tutorial right away, straight from Apple. I’d much rather actually create something than just read about creating something, so yay. I downloaded Xcode from the app store and got started with the tutorial right away.

I got through building the UI without much issue. The storyboard in Xcode was easy to use (it’s just a GUI) and with the tutorial telling me every single step….wait, I did notice that the tutorial is for an older version of Xcode. Some of the menu items, detail panels, etc are different than what the tutorial says, but I found my way around just fine.

The second section was about connecting the UI with code. Unlike the first section, this part required me to write some code. Woot, day 1, I am coding again! Maybe you can teach an old dog new tricks, suddenly my past life as a developer seemed like it was just yesterday. Except I did keep putting a semicolon after each line…that’s a C# habit. So I was churning through the tutorial, stopping when it told me to to make sure it worked, and it always did. Until it didn’t. I got to the end of the second section in the tutorial, brought up the simulator, and expected to see the app work. When I clicked a button, nothing was happening. The text in the input box was supposed to replace the text of a label above the input box. Instead I kept getting an unhandled exception and the app just went blank.

I started out by googling the exception, and a lot of the results were about a memory leak. Hmm, that didn’t seem very likely to me. This was a really simple app. My past experience tells me that googling an exception will not always send you down the path of finding the right answer. Usually it’s something a lot more obvious.¬† So I went back through the tutorial with a fine toothed comb. I found one line where I left a semicolon, I thought that was the issue – but nope. I took it out and still had the exception.

I ended up opening the demo code from Apple and comparing it to mine line by line – STILL nothing! I had nothing wrong in my code, so what the heck was the problem?! This is where I started to get frustrated. Coding requires so much patience. Sometimes you spend hours untangling something so simple – but that’s how you learn. So I knew this was a great learning experience, but that doesn’t make it any less frustrating.

A few hours later I realized that for one of my labels on the storyboard, instead of control + dragging it to the ViewController file, I just typed in the code that was auto-generated by doing that same action. I incorrectly assumed that control + drag only wrote the line of code. Apparently it also makes an output association behind the scenes with the storyboard.

Today’s lesson learned: there is stuff being done behind the scenes in XCode when you use the storyboard that you can’t shortcut with a line of code (at least not within my limited understanding).

Whew. Here’s to less frustrating (yeah, right!) days ahead.

My coding setup in the RV. The pink marble thing is my laptop, and I have a big monitor.