Wednesday, June 1, 2011

First iPhone app live !!

Today my first iPhone app is available in the AppStore. This app was created for Zakelijk Rijden which is an online app for car milage administration. In the Netherlands if you drive a car for business you have to keep an administration if you don't want to pay additional tax.

This app was developed in 5 weeks and was approved by Apple without any comments. Not bad for my first app. The only specifications I had was an almost finished Android app which I had to 'copy' to the iOS platform. All 6 screens were made in 1 day. Implementing the functionality took approximately 13 days. When testing the app I found a bug which caused the app to crash. After debugging for 2 days I still had not found the exact cause of the bug. It was clear however that it was CoreData related, so I decided to rewrite the whole CoreData interaction which took another another 3 days. Another few days to add the final images and fix a few issues and the first release was ready to be published.

Keeping to iOS UI Guidelines
Since I was just 'copying' an Android app to iOS, I also had to copy the Android design. Apparently for Android there are no strict UI guidelines, but I wanted to keep to the iOS guidelines which ment I had to change the design on some places. For example, the Android app has a row of 8 buttons for favorite locations. I wanted to keep the button size the required minimum of 44x44 pixels so these buttons did not fit on the same row for the iPhone. Although now beautiful, I solved this by placing the buttons in a horizontal UIScrollView so I did drastically had to change the design.
Since iOS does not have a checkbox component, I also had to change this into a segmented control which took a lot more space then the checkbox on the Android.

Custom TableView cells
The TableView shows all registered trip with startpoint, endpoint and any number of waypoints. This ment that the cell height would depend on the number of waypoints. It took quite a big of googling and trail and error testing to get this done, but in the end I got it working by calculating the height of all lines in the cell and even support line wrapping. The clue here is that you need the text, a font with a size and the bounds in which the text must be put. You can then calculate the number of lines needed and use this with the font height to determine the height of the text.

CoreData bug
A CoreData problem was causing the app to crash. It occurred when the location was changed multiple times before continuing to the next screen. Each time a new location entity was created, but in the end only 1 entity set on either the trip or waypoint entity. In iOS however, the CoreData entity is already created in the db when an entity is created. Unlike in Java when the db record is only created when the transaction is committed. Somehow creating all these Location entities confused CoreData and the app crashed when saving the context. I could not find anything in the iOS docs or on the net about this constraint. In the end I rewrote the whole location setting so the location entity would only be set when the user goes to the next screen.

I'm very much a TDD practitioner. For iOS however I found it difficult to find good resources how to do and setup unittesting. Even though I started with several unit tests which tested the server interaction implementation, at the end I wrote less and less tests. Because I did not have a continuous integration environment (at the time I could not find anything about setting up Jenkins/Hudson/Teamcity/Bamboo to run iOS unittests) I had to run the tests manually and well ... in the end you forget or you just don't want to because it takes too long. An after a while and after some refactorings lots of tests did failed. Because of the deadline I did not fix them anymore.
I wonder why the iOS unittesting knowledge is so scarce on the net. Is it so complicated that everyone want to keep this knowledge for himself, does it give a good iOS developer/company an advantage so they won't share it or is there really so little people around who know how to do this?