Last week I went out to San Jose, CA to go to Apple’s iPhone Tech Talk World Tour!
Apple once a year holds 9 single day “Tech Talks” across the world. This year only 3 were in the US and I was lucky enough to get a spot at the San Jose meetup. The conference was focused on getting developers to use best practices in all regions of their applications. Apple’s stance was even if the app is small, it might as well be designed as well as possible.
The day started with a nice overview of the iPhone platform. They sell tons of these things and people seem to love the App store. No real news there. Nice overview of the creative apps in the store. Certainly got everyone’s brains working for an exciting day.
After looking over all the sessions I decided to spend my whole day in Room A which seemed to focus on the performance, threading and data management. The main tech point to take away from the conference was how threading is done on the iPhone. Apple’s goal is to abstract away the complexities of classical threading. I went to an hour session on it and the only times I heard the words semaphore or lock was the speaker saying that they didn’t exist anymore.
The iPhone has may build in calls which are blocking calls. This means that when performed on the main thread functionality will halt until they are done. A very commonly used blocking call is initWithContentsOfURL:. This method is used commonly for XML parsing and grabbing images from the internet. Apple has created a solution for this that essentially automizes your thread management with a single line of code. Lets say for example I am creating an app that on launch parses an XML source. If I have a containing method called parseXML() that does all the parsing I can call this method on a managed thread simply by using.
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(parseXML) object:nil]; [queue addOperation:op]; [op release];
That’s it. Apple has made a general class called NSOperation that gives users the power to create their own automated threading classes. In this case I am using the built in NSIvocationoperation object that takes in a method and runs it on a secondary thread. Throw the operation into an operation queue and you are done. Very powerful stuff.
Aside from the fun tech stuff it was a great opportunity to meet people in the developer community and share ideas.