Define the app delegate as a constant?

2019-06-27 15:58发布

问题:

I'm trying to write an iPhone application, and I have a problem.
I have declared a constant as the app delegate inside a class

#define ikub (iKubMobileAppDelegate *)[[UIApplication sharedApplication] delegate]

And when I need to get the size of an array, which is an instance variable for the application

[ikub.subscriptions count]

I get an error Accessing unknown 'subscriptions' getter method.
I'm not really sure why this is happening.

Please help!!!!

回答1:

You need to wrap your macro value in parentheses (otherwise, the cast within the macro applies to the property, which at that point is unknown.) So:

#define ikub ((iKubMobileAppDelegate *)[[UIApplication sharedApplication] delegate])