I have a universal app and for each device (iPad, iPhone) have different sets of properties like this:
//iPhone
@property (nonatomic, strong) CategoriesViewController *categoriesViewController;
//iPad
@property (nonatomic, strong) UIPopoverController *categoriesPopoverController;
But I don’t want to waste memory synthesizing properties for each device. Like in my case when user opens app with iPhone, only iPhone specific @properties should be created. Also wice-versa for app running on iPad.
Is there any directive in compile time to defer this, something like that:
#if UI_USER_INTERFACE_IDIOM() = iPhone
//create iPhone properties
#elseif UI_USER_INTERFACE_IDIOM() = iPad
//create iPad properties
Is there any way to do this or is there a better way to handle this?
Thanks!
There is no way to do exactly what you’re asking.
Is this extra memory usage really significant? A property like that is only 4 bytes per instance of your object. If it’s in something like a controller, where you have only one (or a few) instances, then this is not even worth talking about.
If you really need to do this, consider making an abstract base class, then make subclasses for the iPad and iPhone versions. At runtime, use
UI_USER_INTERFACE_IDIOM()to decide which class to instantiate.