Sunday, September 8, 2013

iOs Programming

iOS Programming


          It's been a few weeks since I've written anything and I've been missing these posts as a creative vent for structured periods of work. The process that I've locked on has been to set aside an hour or two to do an activity (program, guitar, read, etc), do said activity in silence, and then write about what I've learned from it. It feels like a good structure and allows me to really focus on what I'm doing and then digest it through writing afterward. The biggest challenge is making sure I stick to that schedule. 

          Tonight's activity was an admission of sloppiness. As you can see from my personal website (still in the works), I've worked on a few iPhone apps for various people and have learned a lot from those projects. Recently, I've been working on one that deals with an established servers with pictures stored with accounts  and is supposed to retrieve them after the user has logged into the app. It's not a huge project and in comparison to the scope of my last project, it seems fairly easy but I've had some major hiccups in it. My first few projects in Xcode were made by using what I knew about C and C++ and combining that with random tutorials that fitted my needs for those specific instances within the app. This worked for one app,  but not with the other. 

         My professors have always warned me of becoming a sloppy coder and to avoid taking shortcuts in learning new languages. Up until recently, I had no reason to believe this would ever be a threat to me as most of my projects had been school ran or at least text book ran, but I see now. This latest project has shown me that my understanding of the View, Controller, and Model method of programming for Objective-C has been set about all wrong. 

          I remember reading about this style of programming in the Apple Documentation but it didn't really occur to me that it was any different from Object Oriented Programming (OOP). When I started creating the app about the accounts and pictures I realized that I had overlooked some really important aspects of design. The first thing that I learned was his system is meant to keep objects in objects and maximize efficiency and reusability. It's standard knowledge that OOP is for efficiency and reusability but Apple's model takes it even further. Objective-C wants you to handle your programs like factory workers and management and really break up the process, but it makes sense. 

          Firstly, you think about the variables as models. Models are Apple's way of creating a visual way of imaging storage such as arrays so that the programmer can see what they have to offer. For instance, if we were to store a list of questions like "What color is the sky," "How many seas are there in the world," and "Why ask so many questions," we would store these in an array and create a pointer instance variable to reference them. So far, there isn't very much of a difference but it gets better.

         Next, we have the Views and the Controllers. To simply put it, the Views are what you see and the Controller...controls! It's so easy but the exchange of information is extraordinarily quick. Your view on your phone is what you see: the buttons, labels, pictures, etc and your Controller is what handles the processes between the Views and the Models. For instance, the View knows that it's supposed to be displaying a label with the question variable but it doesn't know where to get it from so it asks the Controller. The controller knows that it's variable is pointing at an array that holds the questions so it grabs it and passes it back to the view to display. Both the Model and the View act as single minded drones that only do one thing apiece: the Model stores, and the View displays. 

         This model of exchange doesn't seem that crazy of a concept but it makes a huge difference when you're taping together all of these Controllers which are conflicting with each other and causing heaps of errors. Tonight, I accepted my lack of discipline and settled to reread a book that I've had in my possession for some time but have never brought myself to get to the Big Nerd Ranch Guide to iOS Programming. It's a pretty good book but most importantly it stresses the process of design and that's something that I really wanted to refocus on. 

          Having a schedule and sticking to a format is good practice for life and programming. I hope you guys enjoyed this and I look forward to writing again soon!


No comments:

Post a Comment