Friday, 28 January 2011

Speaking: BCS Edinburgh (iOS development)


I will be speaking at the Edinburgh branch of the BCS on the subject of iPhone development on March the 9th.

The details of the session, times, and location are available here.

Here's the synopsis:

Developing applications for iPhone, iPad (and other iOS devices)
"An introduction to iPhone development for beginners or those who are casually interested and want a leg up the learning curve"

The iPhone, iPad and their iOS relatives are becoming an increasingly popular and important platform. More and more developers are looking into what the platform can offer and how to harness its power for their products.

In this presentation, an experienced iOS developer provides a boot-strap in iPhone development. The talk is an overview of how to get started as an iPhone developer. You will gain an understanding of the platform, the tools, and the core technologies, including:
  • The main languages: Objective C/C++
  • Using the Xcode IDE, and various deployment/testing tools
  • Common iPhone/Mac OS design patterns, idioms, and practices
  • Becoming a native: how to "think in iPhone"
  • An overview of the libraries and facilities that exist
  • Limitations of the development environment.
We'll see the pros and cons of iPhone development. You will leave with an understanding of how to deploy your applications on the device, and whether it is the right platform for you to target.

Thursday, 27 January 2011

iOS: performSelectorOnMainThread: with two arguments

iOS's NSObject class provides a mechanism to run any selector on a different thread. The most often used variant runs the selector on the "main" (i.e. UI) thread, the snappily titled: performSelectorOnMainThread:withObject:waitUntilDone:. However, the limitation with this call is that you can only supply one argument.

Sometimes, one is not enough. There is a two argument non-thread version, here. So why not invent our own two-argument threaded version?

We can add this easily enough to the base NSObject class by opening a new category on it just for the purpose.

Here's how...

1. Define our API

We open a category on NSObject (note the category name in brackets)
@interface NSObject (PGPerformSelectorOnMainThreadWithTwoObjects)
- (void) performSelectorOnMainThread:(SEL)selector withObject:(id)arg1 withObject:(id)arg2 waitUntilDone:(BOOL)wait;
@end
Naturally, it follows the existing performSelector API signatures, but just adds our extra withObject: argument.

2. Implement it

Here's the secret sauce. Careful application of NSMethodSignature, and NSInvocation.
@implementation NSObject (PGPerformSelectorOnMainThreadWithTwoObjects)
- (void) performSelectorOnMainThread:(SEL)selector withObject:(id)arg1 withObject:(id)arg2 waitUntilDone:(BOOL)wait
{
NSMethodSignature *sig = [self methodSignatureForSelector:selector];
if (!sig) return;

NSInvocation* invo = [NSInvocation invocationWithMethodSignature:sig];
[invo setTarget:self];
[invo setSelector:selector];
[invo setArgument:&arg1 atIndex:2];
[invo setArgument:&arg2 atIndex:3];
[invo retainArguments];
[invo performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
}
@end

That's it.

Now you have your own simple way to invoke a call to selector on the main thread from wherever you are in your code. Handy.

Wednesday, 26 January 2011

Speaking: ACCU 2011

I will be speaking at the ACCU 2011 developer conference in Oxford, UK in April.

This year, my ACCU presentation is called Becoming a Better Programmer (yes, following the title of my magazine column - but it's not the same content, honest!).

Here's the talk synopsis:
You're a programmer. You spend your life programming. (You dull person, you!)

Don't you want to do it as well as you possibly can?

This entertaining talk will provide a number of practical, simple methods to become a better programmer. There will be plenty of hand-waving and jumping, a little philosophy, and much wisdom from our excellent programmer forebears.

Be the best programmer you can!

Reflections: The year that was

I'm a bit late to the table with this one given that we're almost a full month into 2011, but it's always good to take stock of what you've achieved in a year. And: better late than never, eh?

I was prompted to perform this exercise by a few other people's similar posts; perhaps you'd like to do the same thing?

I'll admit that I actually began writing this list at the end of last year, but have only just got around to finishing off my notes. Enough with the procrastination. I seem to suffer from a bad case of everything-is-more-important-than-everything-else-itis recently.

Amongst other things, in 2010:
  • I continued writing my regular software development column for ACCU's CVu magazine. This year I renamed the column, from the slightly stuffy and ambiguous "Professionalism in Programming" to the more lucid "Becoming a Better Programmer".
  • Speaking at developer of conferences. I gave two talks at ACCU 2010 in Oxford, and one in the Software Craftsmanship track of QCon London 2010. I also gave a presentation on iPhone development for Software East in Cambridge. It was refreshing to attend other techie conferences as a "mere" attendee.
  • Book contributions. I contributed three entries to O'Reily's 97 Things Every Programmer Should Know book, edited by Kevlin Henney.
  • Kept on developing... Produced a number of iOS apps for my company (DJ apps, Synths, and a hardware MIDI SDK). And worked on Mac apps, getting them available in the Mac App Store when it launched.
  • Kept on developing more... It's been gratifying that a lot of my publicly available code components have been very popular in 2010. Especially the iOS MIDI I/O library I wrote which has found its way into many iOS apps, and my work getting the Boost libraries easily available on iOS.
  • Continued graphic design and layout work, overseeing the layout and design of CVu and Overload magazines, as well as producing the covers for both publications.
  • Performed a number of techie book reviews. Mostly this year, I have been reviewing iPhone/iOS development books for ACCU.
  • Learnt new technologies: this year was definitely the year of git, which I now use for everything, including accessing Subversion repositories.
  • Preached on a Sunday morning at Old Windsor Parish Church.
  • Spoke at the wedding of two great friends, Steve and Frances.
  • Playing keyboards at three conferences in Cambridge (as well as regular stints in the Sunday morning band at C3).
  • Leading a smallgroup at C3.
  • Moved house (I now have a studio, wooo!)
Phew! That list's not exhaustive (I wonder what I've forgotten about), but its enough for now. It's been a busy year. And not a dull one.

2010 albums of the year: Bonobo's Black Sands, Brandon Flower's Flamingo, Foal's Total Life Forever, Seasick Steve's Songs for Elisabeth, Vampire Weekend's Contra, 65daysofstatic's We Were Exploding Anyway, St. Lola In The Fields' High Atop The Houses And The Towns, Lou Rhode's One Good Thing, Jonsi's Go, Goldfrapp's Head First, and Klaxon's Surfing the Void.

Friday, 14 January 2011

Writing: When It's Done, It's Done

The January issue of ACCU's C Vu magazine is out now. It contains the latest installment in my Becoming a Better Programmer column. This one's called When It's Done, It's Done, and is a description of how to do the "right" amount of work; to work out when your current task will be complete, and when you should stop working on it.

The magazine should have landed on ACCU members' doormats already. The PDF version is available for download on the website.

This is the first issue of C Vu for which I have produced the cover using Photoshop (previous issues were drawn in The Gimp). Most people probably won't notice, although I took the opportunity to make a few small visual tweaks. Ironically, Paul (the guest editor) asked me for a cover that was a bit "Java-y", and then there were no actual articles about Java. Ah well...

Wednesday, 5 January 2011

More iOS MIDI (using networked MIDI connections)

My iOS MIDI I/O example code has been incredibly popular. It's great to know that many music apps out there have incorporated my code to get their MIDI interfacing working.

Thanks for all the kind feedback.

I have been updating the MIDI code with a few structural tidy-ups, and an often requested feature - the ability to use networked MIDI sessions (connections).

Doing it manually: Using networked MIDI connections

iOS provides some a neat networked MIDI connection facility. However, despite being easy to set up, network MIDI sessions aren't initially obvious.

First, you must include:
#import <CoreMIDI/MIDINetworkSession.h>
Because network sessions are not included in the umbrella CoreMIDI.h include file. Sigh.

Next you must establish a network session by winking the (evil) singleton instance into existence:
MIDINetworkSession* session = [MIDINetworkSession defaultSession];
Then, merely turn it on:
session.enabled = YES;
session.connectionPolicy = MIDINetworkConnectionPolicy_Anyone;
Yes, that is all.

Documentation for MIDINetworkSession is available here.

The easy way: using PGMidi

If you're using my MIDI classes, then you can just call the PGMidi class' enableNetwork: method with YES or NO.

Get the code

The latest version of my MIDI interface code, and a sample project that shows it in action is available from the GitHub project page.

Feedback, as ever, is welcomed.