Beautifully-formatted Times and Numbers

Example of rendered proportional numbers and monospaced numbers

Example of rendered proportional numbers and monospaced numbers

Not all font instances are created equally! In iOS text is mostly displayed using proportional fonts, meaning each character width is trimmed and varies depending on each character. This makes the text easier to read and feel more natural and you’ll notice this on characters such as ‘i’ which will often be the thinnest character compared to say an ‘m’ character. However for numbers displayed in a tabular format such as times, figures and currencies you’ll want monospaced characters so you can tidy up the layout and visually scan the data quickly. So how do you do this?
Continue reading

Bluetooth 4.0 LE – The Bluetooth Renaissance

Bluetooth 4.0 LE LogoSometimes a technology comes along that seems like such a good idea you wonder why it was never created in the beginning. For me, Bluetooth was one of those technologies. It’s been around since the late nineties and was incredibly powerful, especially for PDAs and phones but has always been overshadowed by the complimentary WiFi standard and surprisingly inflexible Bluetooth profiles which define the protocol, format and intended use of the data being communicated such as a Modem profile or headset profile.

It’s strength lies in allowing devices to talk to each other over a short distance with low energy and relatively easy setup but while many developers, makers and designers hoped to make use of it as a “wireless USB cable”, the reality was that most uses didn’t fit within the defined “profiles” and so developers opted for the Serial Profile – a generic profile that shuffles bits to virtual serial ports. Serial ports are decades old and because there is no context of what the data is inside the Serial port it’s very easy to bind the wrong program to the wrong device. For example, a data logging program trying to read the serial data from a serial port joystick would probably work or worse still would most likely silently do nothing. This adds confusion and frustration for the user. Compare this experience to using a USB device – you plug it in and open up the program and it recognises the device and starts using it. You don’t see incompatible devices, you can’t connect it to the wrong thing, it just works which is probably why USB is so popular.
Continue reading

Apple WWDC 2012 Session Videos Live

This is a heads up for anyone who does iPad or iPhone development; Apple have made available their awesome WWDC 2012 sessions videos to developers! iOS 6 features such as Passkit, maps and Facebook looks interesting as does the new Game Center functionality such as “Challenges” along with a whole host of new APIs and technologies. More information can be found on the Apple iOS 6 site and the developers’ iOS 6 overview site.

You should also look at the new OS X technologies in the soon-to-be-launched Mountain Lion release. Notification Center seems like such a natural addition that I’m surprised Apple didn’t add it in back in the early days of Mac OS X and Game Center will be exciting to play with on the Mac. I just hope it doesn’t distract me too much from work!

Of course most of it is still under a non-disclosire agreement so only blog and comment about the publicly announced WWDC stuff but this will good to play with over the summer when it’s too hot to be outside.

How to call a block after a delay

On iOS and on OS X you sometimes need the User Interface to update after a short delay. The old way of doing it was calling the performSelector:withObject:afterDelay: selector on any NSObject subclass but that requires defining a new method in your class and you can only pass one object as a parameter.

Instead, you can use dispatch_after from the Grand Central Dispatch APIs to execute code within a block after a certain time interval. Don’t be afraid, it might be low-level C but you can cut and paste and just put your code inside and it will retain the variable scope that blocks usually do!

double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

  // Your code here

});

Reverting your library from a beta of iTunes

As an iPhone and iPad developer, Apple often present you with beta versions to install which sometimes require you to also install a beta version of iTunes. Of course the contents of these beta versions are under strict non-disclosure agreements but the process of rolling back isn’t so I’ll quickly explain how to do it…

When you installed the beta, it will upgrade your iTunes library database but if you try to downgrade back to the old version at a later date you’ll be presented with an error message saying that iTunes cannot read your library.

Don’t panic! The beta version has just moved your library database to a backup folder and with a simple drag and drop you can have your old library database up and running again. Your old database should be found in ~/Music/iTunes/Previous iTunes Libraries dated with when you upgraded. Just drag that back into ~/Music/iTunes renaming it to iTunes Library.itl (you’ll probably need to delete the existing iTunes Library.itl file too as that belonged to the beta version and you just uninstalled that).

That’s all you need to do to get your old iTunes library working again. Just before you begin make sure you back up everything!