Objective-C load and initialize

These two static methods of an ObjC class allow you to run initialization logic where you can set up any static state. Both methods are only invoked if implemented and do not need to be declared in the interface of your classes. The differences between them are as follows:

  • In an application, or in a framework that links to an application, the +load() method is executed before the main(). In a loadable bundle, that same method is executed during the loading process. Instead, the +initialize() method is executed lazily before the first use of the class it belongs to.
  • There is no autorelease pool in place when the +load() method is executed, so if using any autoreleased objects you will have set one up yourselves. The +initialize() method runs in the same context as the first call you make to the enclosing class, so there will most likely be an autorelease pool present.
  • Because the +load() method is executed so early, you have to be careful because not all classes you rely on might have been loaded. All frameworks you link to are guaranteed to be loaded first, though, so you can rely on the classes they define. No such concern is necessary when using classes from within the +initialize() method.
  • Unlike all other cases (including the +initialize() method), when redefining a +load() method in a category, you will end up with all defined loaders being executed when an application starts or a bundle is loaded.

Ports and processes in Ubuntu

This command will show what processes are currently listening on what ports on your Ubuntu box:

Result of netstat
The result of netstat

sudo netstat -lntp

If you have installed nmap (sudo apt-get install nmap), you could also run

sudo nmap -A -T4 localhost

Result of nmap
The result of nmap
to try and find out the name and version of the services running on each port.

The output of netstat above will give you the number of the process (pid) as well as the name. You can then use

sudo ps -f -p

to find out more about the process (for example the command line arguments passed to it) and this

sudo kill -9

to kill the process brutally (if you have no other means) and release the port in question.

Custom configuration for Plesk domains

If you ever change your web server configuration files under Plesk manually, your changes will be overwritten the next time you use the administration console and apply any settings through it. This can be solved by adding a configuration file to your domain config folder


or subdomain config folder


depending on which element you need to apply custom configuration to.

In order to make these files effective, you need to run a Plesk command that will detect the presence of the new files and include them in your domain’s main config file (they are not by default). You can do this at the specific domain level

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=<yourdomain.com>

or just reload all domain configurations at once

/usr/local/psa/admin/bin/websrvmng -a

You can now safely keep on using the Plesk administration console and be sure that your custom configurations will not be overwritten or affected in any way. This information definitely applies to Plesk 8.2 where it has been tested, but should work equally well on previous and possibly later versions.

iPhone apps and device language setting

Though it is possible and even relatively easy to create an iPhone app that uses a different language to the one set in the device settings, the feature is not very well documented and it can take a while to work out how to use it properly. Continue reading “iPhone apps and device language setting”

Redeem an AppStore coupon from outside the US

DEC 2010 UPDATE: This article is now obsolete. Apple changed their policy and promo codes can now be redeemed in any App Store worldwide
If you have received an AppStore coupon for an iPhone/iPad/iPod Touch application, you will only be able to download your free product if your account is based in the United States. Here’s a few simple steps you have to follow in order to access your goods, regardless of where you are… Continue reading “Redeem an AppStore coupon from outside the US”

Custom SQLite build and iPad

I have built my own SQLite3 library in order to enable support for full text search for my iDEX app, I compiled and tested on iPhone (iOS 3 and 4) with no problem, but then I switched to the iPad target of the same project under iOS 3.2, where the application would crash as soon as I accessed any of the tables in the database. It seemed like the app was not able to see the tables (also see here), and a more accurate research revealed that the problem was more complex (see this). I have put two and two together and have come to my own conclusion: the problem only presents itself when building against iOS 4 and deploying to iOS 3.2 on the iPad. As my application has separate targets for iPhone and iPad, I just changed the Base SDK of the iPad target to iOS 3.2 and re-built. It works a charm… It doesn’t in any way solve the problem and it requires that you set up a separate target for iPad, but at least you can submit the app! I have spent hours researching this, so I thought I’d share 😉

Base SDK, Deployment Target, Weak linking and import

With the new release of Xcode for iOS 4, I was disappointed to find out that it’s not possible to select versions of the iPhone SDK prior to 3.2 from the usual build drop-down box. So I decided to take the annoying opportunity to find out more about how to create applications that use a certain level of features (eg, iOS 4) while still running gracefully on previous versions of the operating system (eg, iPhone OS 3.0). I have wanted to get to grips with this for a long time. Given that you need to tweak these settings more consciously with Xcode 3.2.3, I suppose now is the time. Continue reading “Base SDK, Deployment Target, Weak linking and import”

Longitude and latitude from Google maps

Do you need to know the coordinates of somewhere in the world? Open up Google Maps at maps.google.com, find the spot you want and make sure it’s centred in the map, then run this simple JavaScript command in the address bar of your browser…

javascript:void(prompt('Latitude : Longitude', gApplication.getMap().getCenter().lat() + ' : ' + gApplication.getMap().getCenter().lng()));

The latitude and longitude will pop up on you screen for you to copy and paste…

Internationalise your iPhone apps with Xcode

There are only a few simple steps to follow in order to make an iPhone app easily adapt itself to the language and cultural context of the device, and with Xcode you can quickly add the features that make your code internationalised. But let me set the scene first by briefly clarifying what is meant by internationalisation and localisation. Continue reading “Internationalise your iPhone apps with Xcode”