I bought my first iPad 2 years ago. A year later I bought an iPad2 and a little later an iPod touch as my “iPad to go” (it’s just more pocketable).
Having downloaded about 70 apps over time (free and paid apps), I found that some apps are doing exactly what I want, some overfulfill my needs and some just didn’t work as I expected.

But, after 2 years of app consumption, I finally got the idea that I wanted to have apps exactly how I wanted them. So I decided that I want to program an app.
So I challenged my self – as a personal DIY-Project – to learn iPhone programming.

This instructable will show off my finished app “Gas By Numbers” (a gas calculator), it’s functions, how to use it, and how I became an “app-developer” from scratch.

My gas calculator follows the steps I undertake when I fill up my car. First I note down the mileage, then I start refilling my car and already note the gas price while refilling. Finally, I enter the amount of gas I refilled right after hanging up the nozzle of the pump. While I go in to pay my bill, I already know my gas mileage.

The first bullet points will show how to use the app itself (always headed off as App-Step X). Below I will comment on some programming features needed or additional thoughts that went into programming the specific UIView (always headed off with Programming).
I have quoted the “app-developer” because this is my first app and there’s so much more I can learn from here.

To complement this instructable, I especially tweaked my app so I can offer a free download on iTunes with "free Gas By Numbers".
In the free version I have stripped off the data collecting part of my gas calculator, and the calculation of the gas consumption and cost of the daily commute. So the free app actually resembles the program how I initially wanted it to be just for my own use.

Link to the free app:

Link to the paid app:

All the other stuff within the paid version came later to mind as I was thinking about distributing my app via iTunes (think about localizing an app for different countries, adding functions that may be interesting for potential users, etc.).

The last step will tell you what you need to start programming for iPhone and some (hopefully useful) hints and tips to start learning programming.

Step 1: Entering the Driven Distance

App-Step 1:
  • In the first view, tap the text box to pull up the on screen keyboard and enter the number of miles driven since you last refilled your gas tank.
  • After filling in your driven miles, hit the next button to get to the next screen.

  • All visible windows a user will see are called UIViews. You can put all your code into the UIViews class.
  • First I wanted to add all user input fields on the first UIView (maybe even the results of the gas mileage calculation). But I soon found out that the space on a UIView is very restricted and that the User-Interface (UI) will be much too crowded as to be a pleasure to use for a user.
  • The problem I encountered first was, that I didn't know how to hand over the inserted mileage to the next UIView. So I needed some temporary storage for that data. The rescue to this problem if you want to store small chunks of data is to use the so called NSUserDefaults in Xcode.
  • To ensure that the user entered a valid number in the distance text box, I had to check the number after it was inserted. All keyboard input is represented as a NSString in Xcode. So the program doesn't even know it's a number. To ensure the user didn't enter a number with two colons, for example, I casted the string into the so called NSNumber format. This way, you can error check the input.
  • To ensure the user cannot enter letters instead of numbers, you can specify to only show a number pad within the code.
  • NSNumber will also take the locale settings into account, making sure a european user has a colon as decimal separator while the US separator is a point.
  • If the error check results in an error, a so called UIAlertView is programmed. This is a nifty little line of code, where you specify the header of a pop-up message, the message itself and some OK, Cancel or "Take action" buttons.
<p>Thank you for this!</p><p>I'm just starting out as a developer, so a step by step on how and why to do things is very appreciated.</p>
Thanks for your feedback. In the meantime I have quit programming due to different reasons. The main reasons were the hassle with tax preparation (depends on the country you live) and the requirements of the app store with pretty strict guidelines that had to be followed. Besides having a full time job, a 2 hrs daily commute and a family, getting all this crammed into one day was quite intense. But it was a great personal challenge. If you have more questions I can try to help.
I never understood why people calculate their gas mileage. The only time I can imagine it would be of any use would be if your gas gauge is broken. Other than that when you run low you either buy more gas, or don't drive. Knowing how many miles you're getting a gallon doesn't get you another foot down the road. <br> <br>Today you can't even make the case for engine tune ups. Cars just aren't like that anymore.
Well, I never understood why people need fast cars... <br>But that's not the point here. I wanted to know how much I pay in average on a per day basis just to go to work and back. So I need to know how much gas my car consumes. <br>My app is even keeping track of all the data. <br> <br>I agree that I go and refill my car when I'm running low on gas, but I'm also carpooling so just keeping track of how much I have to pay per month is easiest by tracking the mileage and the price... <br>...so there you have it. In this case you want to calculate your gas mileage (or gas consumption) ;-) <br> <br>And this is maybe even more important for people who need to be careful about their spendings.
cool, will you post the source code for this?
I'm not sure if posting the source code is a good idea. Even if it's a rather small program, the code is quite lengthy. <br>But if you're interested ... <br>... now I'm trying to be funny (sorry, I couldn't resist): <br>and don't just want to change the color of the background and then release it as a competing app, <br>... funny off <br>I can try to extract the different classes and pm them to you. <br>Unfortunately, there are already so many competitors, I wish I would have checked before I started programming ;-) <br>The interface was made utilizing InterfaceBuilder, so that wouldn't be included in the code (well, to some extend as the app is set up multilingual). <br> <br>Duuh. I also had forgotten to post the link to the free app. So thanks for your comment. This way I saw it was missing :-)
thanks for the info, if you decide to post it you can attach it to a step the same way you add pictures to a step. If you put it all in a zip file it won't be so much stuff.

About This Instructable




Bio: I rather like "to make" than "to consume". I've been programming for iOs for a while just to see if I can. I love ... More »
More by Mike73:Fake Halloween Tombstones Kids room remodel My first own iOS app - Gas By Numbers - a gas mileage calculator 
Add instructable to: