Custom delegate example?

I’m making an iOS app.
I found partial examples(with only objective-C delegate implementation), but couldn’t find complete project which implements custom delegate class.
Could someone show me simple example?

My main problem is, I have no idea to pass objective-C interface to macro’s argument (START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass)).
So, how can I implement at .h and at .mm?


I notice START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE should be wrote in .mm file! It works fine now.

I created project as ‘GUI Application’ so I was obsessed to write it in Main.cpp.
My implementation became like that:

#import <UIKit/UIKit.h>

#include "Main.cpp"

**@interface** MyCustomDelegate : NSObject <UIApplicationDelegate> { NSObject<UIApplicationDelegate>* juceDelegate; } **@end**

**@implementation** MyCustomDelegate

-( **id** ) init


**self** = [ **super** init];

juceDelegate = **reinterpret_cast** <NSObject<UIApplicationDelegate>*> ([[NSClassFromString (@"JuceAppStartupDelegate") alloc] init]);

**return** **self** ;


-( **void** ) dealloc


[juceDelegate release];

[ **super** dealloc];


- ( **void** ) forwardInvocation: (NSInvocation*) anInvocation


**if** (juceDelegate != **nullptr** && [juceDelegate respondsToSelector: [anInvocation selector]])

[anInvocation invokeWithTarget: juceDelegate];


[ **super** forwardInvocation: anInvocation];


-( **BOOL** ) respondsToSelector: ( **SEL** ) aSelector


**if** (juceDelegate != **nullptr** && [juceDelegate respondsToSelector: aSelector])

**return** **YES** ;

**return** [ **super** respondsToSelector: aSelector];



// "MyAppliccation" was declared in Main.cpp