BuySellAds.com

If you like my tutorials, you will love my book . It is chockful of advanced programming techniques and the only comprehensive barcode reference for serious iOS developers.
Our DNA is written in Objective-C
Jump

Category Archive for ‘Q&A’ rss

Shorter Back Buttons

Today, on the train to the big city, I watched the seventh Standford iPhone Programming lecture and got an answer to a question I’ve been having for a long time.

Can I make the back button shorter in a UINavigationView? I like long titles, but it looks ugly on the back button!

The back button of a view that you pushed on the the navigation stack defaults to the previous view controller’s title. You want to make the title explanatory so a long one is good. But if you push another view controller onto the navigation stack you want the space to have an explanatory title on this one, or you need the space for something else.

Read more

Contacting the App Delegate

Remover asks:

How to send a message from a view controller to app delegate?

That’s a question that everybody asks who is trying to follow the model-view-controller paradigm. There is an easy way to access your app delegate from anywhere in your app.

Read more

Learn to Say No

This request of MKureth is so totally crazy that I just had to share it with you:

Hi, I am currently working 60+ hours a week on highly advanced interactive development which mainly consists of Flash (AS3), XML, JavaScript, PHP, and MySQL. I was asked to learn and develop a working iPhone application using the frameworks of Cocoa, Objective-C, and OpenGL within two weeks. Given my current work schedule and skill sets, how should I proceed with this request and deadline (of two weeks) keeping in mind that I have no prior experience with Mac development?

As impressive as your resumé sounds you lack a couple of essential skills.

Read more

The Best Way to Save Data

BebopSong asks:

Can anyone tell me the best way to create and store data on the iPhone so that the app can read the data but also write to it?

Having tried out all the possibilities that the iPhone platform holds in stock, here’s my opinion.

Read more

NSString Category for Compressing Whitespace

Anonymous users keep asking:

How do I remove whitespace characters from a string?

A quick way to do that is to first split the words in the string by whitespace characters and then join them back together without seperator. But there is a more elegant way to achieve this, that’s reusable at the same time: extend NSString by adding a category to compress whitespace to an arbitrary seperator.

Read more

OpenStreetMap in a UIWebView

Nicholas asks:

I’ve made an attempt recently to incorporate OpenStreetMap into my app. I’ve failed miserably. The result is a blank webpage. Any help/hints would be appreciated.

I immediately suspected that there was wrong with how he constructed the URL for the UIWebView, because I did run into a similar problem before.

Read more

Minimum/Maximum of Multiple Values

MadIvad asks:

Is there some sort of math function for the minimum of a set of values? I have searched the docs and not found one reference to math in iPhone OS2.2, and min only returns the like of ‘minimum’ for different control values. or for stating what the minimum of the integer or NSUInt class etc…

Does a function/class/anything exist that would simply return the lowest value of 2 or more values?

Boy, that was easy. There are compiler macros defined that work on any scalar datatype. MIN(a,b) and MAX(a,b). Note the case.

Read more

Variable Number of Decimal Places

Trapper asks:

I have one integer holding a variable number of decimal places that another variable needs to be rounded to when I stringWithFormat it. What is the correct way to do this?

Trapper is not content with just specifying %.2f in a stringWithFormat, but he wants the number of decimal places to be dependent on a second variable.

Here is the shortest method I came up with.

int decimals = 3;
double d = 3.1415;
   
NSString *format = [NSString stringWithFormat:@"%%%0.1ff", decimals/10.0];
NSString *formattedString = [NSString stringWithFormat:format, d]; // e.g. %0.3f 
NSLog(formattedString);

I got confused at first because the NSLog would always output a strange value when wanted to output the formatting string. Then I remembered that the first parameter of NSLog itself is also interpreting formatting information. NSLog combines stringWithFormat into the output.

That’s good to know in case you want to add an NSLog statement for debugging floating point variables.

double d = 3.1415;
NSLog("%0.2f", d);  // formatting directly here

Don't Quit Your Day Job

Rob asks:

I have decided to start writing apps as a full time job. Assuming I can master this, and assuming I can get 1 app per month accepted in the App Store, can anyone give me some guidance on how much income I am likely to make.

Here are some numbers from my data that might help you:

  • A general purpose tool app like GeoCorder might sell between 1 and 5 copies a day.
  • Something interesting or unusual like iFR Cockpit can expect to sell around 5-10 copies a day.
  • A niche market tool like iWoman might to do well at 10-20 copies a day.
  • A game like LuckyWheel would sell around 20 copies a day IF you also have a LITE Version that has about 900-1000 downloads a day. Without a LITE version it could only be 5-10 copies a day.;-)

So assuming you concentrate on niche apps and games and calculating from $25 a day per such app you might make around $2000 a month if you manage to land 3 of those in the store. NOT taken into account additional cost like taxes or hardware. And not considering that Apple has the painful final word. Does that sound easy enough for you to immediately quit your day job?

For me it didn’t and it took me 8 months to get where I am today. It’s ok to see it as a lucrative hobby or even second income, but to stake your existance solely iPhone development you have to be extremely disciplined. Or even better: to know how to build teams of bright minds who can bring skills to the table that your don’t possess yourself.

How to Start Developing

I keep getting questions about how to best get into coding apps for the iPhone. Do I recommend books? How should one go about this?

I have one recommendation: Only steel good stuff. Download all the samples you can find on the Apple site and look them through. For most of the basic tasks you can find code to steal there, well commented.

But most importantly I recommend you get a mentor. Somebody who is slightly ahead of you in the objC programming game. But not too far ahead to feel annoyed by your questions… 😉

And that’s the last recommendation: learn to ask the right questions. Because if you ask the right questions you will find that …

40% get answered by Apple documentation
40% get answered by Google: somebody has answered the question in his blog or in a forum
15% get answered by somebody more experienced than you directly if you ask
4% you have to discover for yourself … and then hopefully you document your discovery on your blog
1% are bugs that you have discovered by accident :-) Those you please submit to Apple for them to fix.

When I got started with coding objC for iPhone there was next to no useful literature. And now that I have written half a dozen apps and managed to get 4 into the store I don’t think I would ever need a book. Once you know how to read and understand objC code there is nothing really that you need for reference except the sources I mentioned above.

One more thing: try to develop a network of friends who all are sharing coding for iPhone as the same hobby. Of 10 questions I asked in various forums I only got around 3-5 answered usefully. If you remember the SDK 3.0 presentation, you know that more than half of current iPhone developers are new to the platform! So you are in the same boat as most of us. Be strong! Don’t give up!