5 Time-saving Objective-C tips every developer should know

Batman Flat White Coffee

Here’s a quick fire list of 5 time-saving Objective-C tips that every developer should know. Perfect for making time for that extra coffee!

1. Enum shorthand

Enums at their simplest are labelled sets of integers. Where an inexperienced programmer might use a number to represent the download state of an image lets say, e.g. 0 = queued, 1 = downloading, 2 = downloaded, 3 = complete… When using these numbers in actual code a simple slip of the finger on the keyboard and they could easily type an extra digit in their if statement or assignment. These types of errors don’t usually show up when compiling. Even worse, these are usually obscure errors that only reveal themselves at run-time and only then when things don’t work as expected often requiring considerable debugging effort.

This is where enums step in. Enums are really handy and allow you to associate symbols or ‘labels’ with integers. If you type an enum value that doesn’t exist the compiler steps in and reports an error at compile-time instead and Xcode will probably suggest a fix for you if it was a typo! The other benefit of enums is that you can quickly add new values into them and assuming your code doesn’t save the integer to disk your code will automatically work with the new values.

There are a couple of different ways to define enums but the easiest way which will also provide Xcode with some extra compiling hints is as follows:

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

Retro Yeti Escape Game for iPhone and iPod Touch

I’ve just finished developing Yeti Escape for Vivid Reflection, my iOS development company. Yeti Escape is a new Christmas-themed retro game for iOS. The story: Present-hungry yetis have escaped from the North Pole and threaten to ruin Christmas. Pixel Santa must save the day by throwing spare presents at them. Can he still make his deliveries on-time? The game is available now on the App Store and I’ve made a short 2 minute video demoing the retro gameplay and awesome 8-bit sound effects and music so please check it out.

Yeti Escape Demo – 8-bit Retro Arcade Game from Vivid Reflection on Vimeo.

The Yeti Escape game is made in Cocos2D and has Game Center leader board support so you can challenge your friends too. It’s a fun variation on the classic 8-bit arcade shooter. You play by tapping the screen to fire presents from your sleigh, aiming to hit the yetis. Once they consume a present they disappear back to their slumber in the North Pole. If they escape, they eat everyone’s presents and it’s game over. In some ways it plays a bit like a modern-themed twist on the arcade classic Missile Command. As Pixel Santa is moving through the game world, you have time and aim the shot just right to hit the moving yeti. There are a number of different yetis all of differing strengths and speeds which try to escape at different times and if you’re not expecting it you’ll find yourself shrieking as some “super powerful bad-ass” sumo yeti escapes with your last life.

Please let me know what you think about the game in the comments. What’s your best bit about 8-bit retro games?

If you’d like to keep up-to-date on the apps and games I develop, follow @VReflection on Twitter or like Vivid Reflection’s Facebook page. The game has just gone live and Yeti Escape can be downloaded on the App Store now.

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.

iPhone App: Windsock takes off

Windsock Screenshot of Dynamic mapsWindsock app iconWindsock, my latest iPhone app is live in the App Store. It’s a clean, easy-to-use app that lets you check the wind forecast remotely and up to 4 days in advance. I built it because a hobby of mine is remote control plane flying but often there are days when the wind is too strong or in the wrong direction and packing the flight gear, driving down to the park only to find it is too windy to fly was frustrating (the plane has a wingspan of 56″ which is tricky to get out of a car at the best of times let alone when it is windy also strong wind is likely to make you lose control of your model and fly it into a tree or worse).

Instead I built this app to drop windsock markers down on a map and get the latest wind readings for a near-by location so I know if it’s great weather to fly. You can also save it as a site and with a quick glance see the best park or field to fly in. It is also iCloud ready so will sync your sites between devices and has a relative compass mode to help you discover the wind direction – beats throwing a bit of muddy grass in the air!

The app uses high resolution data to give high-resolution readings every 3 hours up to 5 days in advance. Tapping on the detail view within the app will condense the rows to give you a daily overview of the wind readings. I’ve tried to design it to work in two modes, the first mode is more of a quick overview so you can compare sites and decide the best one to go to, the other mode lets you drill down and view the forecast for a particular site.

It’s also a handy app if you do other outdoor activities, such as kitesurfing, windsurfing, paragliding, kite flying or just fly model planes. Please check it out on the App’s website or on the App Store.