简体   繁体   中英

How to organize the variable and methods definitions when developing universal application for iPhone and iPad

I m looking for a preprocessor or something like that that will help me to define variables or methods depending on the device type iPhone or iPad. I found something related here : Preprocessor-IF doesn't work - where it is advised to use

#ifdef UI_USER_INTERFACE_IDIOM
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define IS_IPAD false
#endif

#define WIDTH (IS_IPAD ? 768 : 320)
#define HEIGHT (IS_IPAD ? 1024 : 480)

but suppose I have variables defined in the interface that are to be used separately based on device

Class1 *object1; //specific for iPhone
Class2 *object2; //specific for iPad

Or methods that are used depending on device, how do I differentiate?

You can use as many as objects in any class, the main thing is at which time you are allocating those classes, you will be writing the code, calling the methods, depending on the device.

So this doesn't make any sense, you can have both objects in the class, & declare in the header file. And in the dealloc check before calling release to those objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM