Q:

Use of undeclared identifier 'completionCallback'

I am attempting to identify when a sound has finished playing by using the AudioServicesAddSystemSoundCompletion method.  The 4th parameter expects a C function, which I have implemented below.  I recieve the error message,
Use of undeclared identifier 'completionCallback' (first use in this function) when referencing it.  None of the online examples I've seen has ever used [self completionCallback], and they have no issues.
Where am I going wrong?
-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}

A:

Well, yes. Sometimes, an error messaqge means exactly what it says. completionCallback needs to be defined above playAndRelease.
First option: declare, but don't implement, completionCallback.
void completionCallback (SystemSoundID  mySSID, void* myself);

-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}

Or define it fully ahead of time:
static void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}

-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

See also:

Wikipedia: Function prototype

