0

I was reading a post on accessing the app delegate using shorthand with a macro here

Short hand for [[UIApplication sharedApplication] delegate]?.

The solution to the problem provided was to define the following macro in the app delegate header.

#define AppDelegate (YourAppDelegate *)[[UIApplication sharedApplication] delegate]

My question is how can I do this with a project that has multiple targets seeing as the appdelegate name would be different for each one?

Community
  • 1
  • 1
dubbeat
  • 7,706
  • 18
  • 70
  • 122

1 Answers1

1

T he #define macro is just a string substitution facility in the pre-processor, so I don't think there is much you can do short of defining another macro that has the name for each target's app delegate. The savings in typing to abbreviate the app delegate is not going to be very much, and imo probably not worth the time to do it. And I will editorialize further to say that if you're making enough references to your app delegate to justify abbreviating, I think you need to move some code out of the appDelegate into better factored (possibly singleton) classes. My 2 cents.

Rayfleck
  • 12,116
  • 8
  • 48
  • 74
  • hmmm, good advice. I thought I might of been onto something useful there....oh well. swordfish! :P – dubbeat Apr 19 '11 at 13:55
  • @dubbeat - we have a winner! Not 3 minutes ago, I gave up on the Swordfish thing and erased it from my profile, so you will get the one and only dollar. Now, how do I get it to you? – Rayfleck Apr 19 '11 at 14:01
  • mmmm, give it to the next homeless person you meet & say it's from me :) – dubbeat Apr 19 '11 at 15:58
  • wow, you think just like I do. (You must be a super-brilliant genius with a high IQ). I'll do that. – Rayfleck Apr 19 '11 at 16:11