BuySellAds.com

My book Barcodes with iOS 7 is nearing completion. Buy it now to get early access!
Our DNA is written in Objective-C
Jump

How to become GREAT at iOS Development

I’m interested in getting your questions because answering them helps me structure the material in my head. And there’s a saying that “what you teach you learn”, because of that.

Devin Snipes, an aspiring young iOS Developer asks:

Hello Dr. Touch,

My name is Devin Snipes, I’m 15 years old and I’m an iPhone Developer. I’ve been following your work for a little less than a year, and I’ve grown to love it. Your work is amazing, and I hope to someday be as good as you are in programming for the iOS platform. I currently have a few iPhone applications on the AppStore, but nothing compared to yours.

I’d like to ask you a few questions that will hopefully give me more insight on your developmental skills and how I can improve on my skill.

Well, “You catch more flies with honey than vinegar”. If somebody asks so nicely I’ll usually try to respond with something useful.

1. How did you become so great at programming for the iPhone?

I’m doing it full time only since last December. And before that I was looking at code on most days for a couple of hours. Do you know the rule of 10,000? It says that if you want to be world-class in any field you have to invest 10,000 hours in total. Before I got into developing for the iPhone I was collecting programming time for many years. So I probably reached 10,000 a while ago. But that’s not strictly Cocoa time. At 10 hours a day it takes you around 3 years to reach 10,000. So I’m probably around 5,000 hours doing iPhone stuff.

Read more

Defaults for the Defaults

I previously explained how to use NSUserDefaults to your advantage, basically being the OSX equivalent to the Windows registry. User Defaults are the way how you can persist small amounts of data in a convenient way. They are basically dictionaries that the system takes care of for you with the added benefit of being cached in memory.

Today we’ll up it one notch. Session 124 of the WWDC 2010 videos brought to my attention the fact that there’s also a mechanism to provide default values for the defaults. Up until now I would have retrieved an object from the defaults, checked if it’s nil and then set the value. Consider the following code snipped from SpeakerClock:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *countdownNum = [defaults objectForKey:@"Countdown"];
 
if (countdownNum)
{
	countdown = [countdownNum doubleValue];
}
else
{
	countdown = self.currentPreset.startDuration;
}

This works, but it’s not elegant. Wouldn’t it be great if we could pre-register those values so that a simple retrieval always has a result?

Read more

Dr. Touch #18 – “Bar None”

The iPhone 4 rulez, bar none.

Play

Show notes, aka “my script” after the break.

Read more

Microsoft Wooing iOS Developers

Yesterday I found an e-mail in my inbox that gave me a bit of a spooky feeling in my stomach. Ordinarily such a mail would have quickly ended up in my trash if it weren’t for the details they put in there.

Why would Microsoft be contacting me? They obviously did a bit of digging or reading to know that I created the apps for CCS Publishing. They didn’t bother to check on my references page though. The ACLS app was done by somebody else. But still it shows a fair amount of data mining as they appear to have checked those apps’ rankings and then cross referenced them with who was the real author.

Read more

Understanding iOS 4 Backgrounding and Delegate Messaging

UPDATE: Added handleOpenURL to the flow charts. Added UIApplicationExitsOnSuspend. Untangled some lines.

UPDATE: renamed deprecated handleOpenURL to newer name.

Now that we all are moving our source code gradually to iOS 4 I had to pause and think a bit about where to move which code. A problem that I’m facing frequently when updating a project is that the didFinishLaunching is only called if the app really launches.

That poses a bit of a challenge if you are used to doing things like refreshing images or other files off the internet. An app that is resumed from standby does no longer go through this delegate method. So an app that would always show fresh content upon launch before 4.0 multitasking would no longer load any new content as soon as you build it for 4.0. That’s actually one of the main reasons why I have not yet had time to update MyAppSales to 4.0.

To gain the possibility for “fast app switching” you actually don’t need to do anything. All apps automatically support it because they no longer get terminated if the user pushes the Home button. They get put into a sleep mode while the iPhone still has enough memory for everything else. It’s only if RAM runs out that the OS starts killing apps. There is begins with the ones that have the most memory reserved.

I grabbed the free trial of Omnigraffle and the Non-techie Process Flowchart Stencils by gfraser. Then I researched when all these various delegate methods of UIApplication are being called and drew charts to illustrate the flow.

By inhaling first how it was before multitasking and then upgrading your mental process to backgrounding we can begin to fully appreciate how it all fits together.

Read more

The 3.2 Hurdle of MPMoviePlayerController

Prior to iOS 3.2 your only option for playing videos on iPhone was to use MPMoviePlayerController and only in full screen mode. It made sense because who really wants to look at stamp sized videos on his mobile phone.

The iPad changed all that and brought along several changes in how you can place videos. All those changes also made it into the iPhone SDKs. Here’s a pitfall that you might not have seen if you didn’t upgrade the SDK on one of your iPhone projects.
Read more

Drawing on UIImages

Jayesh asks:

Thanks for your article on UIImage from UIView.

Need one more favor; I am in situation where I want to draw line or area (e.g. rectangle) on UI Image (e.g. Blue print) and save it again.

Basically I will show image and put circle / rectangle on image showing area in blue print and save it.

How should I do that? Can you please suggest approach, sample codes etc?

So the task is to take a UIImage, make it writable in some way and then make a new image out of that for later use. Off the top of my head, I can immediately think of two ways to do that: with UIKit and with CoreGraphics. CoreGraphics has a slight advantage, being lower level, of being thread-safe. But for a simple graphical addition to an existing image I see nothing wrong with UIKit. As usual you should only do very quick operations with UIKit because it requires to be run on the main thread which is the only thread updating the user interface.

Read more

iPhone 4 Landing in Austria

It’s one of these days there the arrival of a new and shiny Apple toy is diminishing productivity to zero. My iPhone 4 arrived at lunchtime and so I spent my afternoon unboxing and setting up my new iDevice.

I had purchased a black 32 GB iPhone 4 on Apple’s UK store. The kingdom is a tier 1 country which got it at the same time as the US. What’s also great is that the empire’s Apple online store sells the variant without SIM-lock. A necessity if you want to be able to use the iPhone 4 as a phone in your home cellular network. Since I ordered Apple added this paragraph to clarify this:

When you purchase your iPhone from the Apple Online Store, you’ll get it SIM-free. So you can sign up for service with the carrier of your choice and change your carrier at any time

My friend Michael Kaye in London purchased the phone for me (32 GB for 599 GBP) and shipped it via parcel service to Austria. This cost me another 60 pounds, but I had insurance and tracking. The latter was kind of weird, because the original carrier Parcelforce handed off the package to FedEx and so I got incomplete and somewhat strange tracking info. But fortunately it turned out fine.

I’m unboxing the iPhone after the back, check out my YouTube video!

Read more

Hacking UIScrollView Gesture Recognizers

As of SDK 3.2 most of the touch handling code in stock controls has been taken out and replaced with this amazing new technology called Gesture Recognizers. This means besides of using them yourself and creating your own you can also fiddle with behaviors of standard controls if they interfere with your own gestures.

I’m currently working quite a bit on something based on UIScrollView and there I found several things that I needed to tweak.

Disabling Pinch

The first modification I did was to get around a bug in UIScrollView.  I did not actually want user zooming in my scroll view, but just use the setting of the zoomLevel to scale images without having to redraw them. And you can only set the zoomLevel to values between min and max.

So, during autorotation, I reduced the min zoom scale, set the new zoom level and then set min and max both to the new zoom. But the problem with this, as of SDK 3.2., is that if you change the min or max zoomLevel property the scroll silently adds a UIPinchGestureRecognizer to itself via the addGestureRecognizer method that now all views have.
Read more

Service Announcement: Upgrading iOS 4 GM

A not-to-be-named friend asked me:

I would like your opinion the GM build. Should I (not sure how) remove it and then load the new iOS 4.0? I know it wouldn’t have the game center, but I don’t use that anyway. I am afraid if I don’t remove, the software will expire (happened on beta 4 and then I couldn’t use the phone (or back up first) until I could load the latest.

If you’re one of those developers that managed to install the iOS 4.0 Gold Master right after Uncle Steve announced it, then you might wonder if you should update to the really final release that came out just now.

Wait! That’s a trick question…!

Read more