Entries Tagged 'Cocoa' ↓

Invoke any Method on any Thread

Fredrik Olsson

I previously wrote a blog post titled Performing any Selector on the Main Thread detailing a convenience category on NSInvoication for easily creating invocation objects that could be invoked on any thread. This category has served me well, and even got traction in the iOS developer community, so I never bothered to stop and think [...]

Tags: , , , , , , , ,

Auto-incrementing Build Numbers in Xcode

Fredrik Olsson

Users and testers will find bugs you are sure you have already fixed. Sometimes they use the wrong version, sometimes your fix is not as good as you thought. Either way a tiny unique version number visible in the app can save you hours of work. Incrementing the version number of your project for every [...]

Tags: , , , ,

The state of iOS Open Source – and what to do about it!

Fredrik Olsson

There is a vibrant community of open source projects for iOS. You need a calendar UI components or a JSON parser? No problem, the projects are out there. Most code out there is of very high quality. Unfortunately the distribution of the code is generally very crude, barely half a step away from sharing code [...]

Tags: , , , , ,

Sync-Async Pair Pattern – Easy concurrency on iOS

Fredrik Olsson

Apple provides many tools for implementing concurrency in your application. NSOperationQueue, GCD, or simply using performSelectorInBackground:withObject: that is available on each and every object, are just some examples. The tools are there, yet implementing good concurrency is hard. The solution I have found is not yet another tool, or framework, but a simple pattern. I [...]

Tags: , , , , ,

Exceptions and Errors on iOS

Fredrik Olsson

Cocoa, and by inheritance Cocoa Touch on iOS makes a clear distinction between what is an exception, and what is an error in your application. This should be obvious since NSException and NSError both inherit from the NSObject root class with no relations at all. Programmer vs. User Exceptions are intended for signaling programming errors [...]

Tags: , , , ,

Future Cocoa Operation

Fredrik Olsson

In Java you have for quite some time had the Future interface for encapsulating an asynchronous calculation. Cocoa has had the abstract NSOperation class to encapsulate asynchronous operations. NSOperation do not have any facilities for returning a result when done as the Future do, you are left to implement this on your own. Which I [...]

Tags: , , , , , , ,

Rewriting a Public Cocoa Touch API

Fredrik Olsson

Cocoa Touch added API for presenting a view controller in a popup bubble in iPhone OS 3.2, the responsible class is named UIPopoverController. One would guess that this new class is a subclass of UIViewController, just like UINavigationController is, but that is not the case. One would also guess that in functionality many ideas for [...]

Tags: , , , , , ,

Performing any Selector on the Main Thread

Fredrik Olsson

Many UI frameworks, including AppKit for Mac OS X and UIKit for iPhone OS, require that all methods to UI components are sent on the main UI thread. Cocoa and Cocoa Touch make this quite easy by providing for example -[NSObject performSelectorOnMainThread:withObject:waitUntilDone:] in Foundation. Making updating the text for a text field a snap: [someTextField [...]

Tags: , , , , , , , , ,

iPad, the Future, and the Luxury of Starting Over

Fredrik Olsson

A luxury that you seldom have in the world of software development is the luxury of starting over. I am not talking about throwing away everything and start from scratch. But just taking what you have, and all the experiences learned. Apply some major refactoring to make what works really shine, and without care of [...]

Tags: , , , , ,

Google Translate and iPhone apps

Fredrik Olsson

The Cocoa and Cocoa Touch frameworks has a really nice function for acquiring a localized string NSLocalizedString(). Just pass in a key and you are done, for strings that are known at least. Sometimes you are getting unknown strings from a data source not under your control, strings representing just a fraction of the text [...]

Tags: , , , , ,

Add some polish to iPhone app start up

Fredrik Olsson

First impressions last, and the very first impression your users have of your iPhone application is the start up. First step is to have a nice Default.png, but not many words spilled on that one, it is well covered in Apple’s documentation. Creating a perfect Default.png is impossible, especially if you have different setup of [...]

Tags: , , , ,

Regular Expressions and Cocoa

Fredrik Olsson

Regular expressions is a powerful tool for solving many problems related to text. It can be misused as any good tool, but there are moments when they are the best solution for a given problem. At those moments the lack of regular expressions for Cocoa on Mac OS X and Cocoa Touch on iPhone OS [...]

Tags: , , , , , , , , ,

Introduction to iPhone development

Christian Hedin

It has been little more than 2 years since the iPhone was first announced and during that time it has managed to make a huge impact on the mobileindustry. Introduction Just recently, iPhone sales figures surpassed all windows mobile phones combined and in several markets the iPhone has been a top selling phone model. Together [...]

Tags: , ,

Adding Sorted Inserts to Cocoa Arrays

Fredrik Olsson

NSArray and NSMutableArray have methods for sorting arrays, NSArray returns new sorted arrays and NSMutableArray can be sorted in place. The sort methods comes in three flavours; using a function, using a selector, or using an array of NSSortDescriptor objects. NSArray admits to sorts being a slow operation, and adds a method pair for comultive [...]

Tags: , , , , , ,

UIToolbars in iPhone OS 2.x

Fredrik Olsson

The new release of iPhone OS 3.0 adds some nice API:s for managing a contextual toolbar. This is well needed as toolbars in the current iteration of iPhone OS is not only poorly documented, it is also quite hard to do right. So I will go over how to do toolbars the right way, for [...]

Tags: , , , , , , , ,