I am looking at the \'Metronome\' sample code from the iOS SDK (http://developer.apple.com/library/ios/#samplecode/Metronome/Introduction/Intro.html). I am running the metro
Using a while loop and sleep to time a metronome is not a robust way to solve this problem as it is likely to produce timing that is jittery and that drifts, as you have seen. I believe the standard way to solve this problem is to use Core Audio (in one way or another) to feed a continuous audio stream containing your metronome ticks separated by the correct amount of silence between them, depending on the tempo. Because you know the exact sample rate, you can time your ticks very accurately. Unfortunately, generating the audio yourself is quite a bit more difficult than what you're attempting to do, but this Stackoverflow question might get you started.