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
- 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.