Skip to content

Instantly share code, notes, and snippets.

@muromec
Last active December 10, 2015 00:28
Show Gist options
  • Save muromec/4351189 to your computer and use it in GitHub Desktop.
Save muromec/4351189 to your computer and use it in GitHub Desktop.
bunch of magic macros to handle cross-device objc code
#ifndef TEXR_CROSS_H
#define TEXR_CROSS_H
#if TARGET_OS_IPHONE
#define IPHONE 1
#else
#define IPHONE 0
#endif
#define on_iphone(x) {}
#define on_mac(x) {}
#define on_ios(x) {}
#define on_ipad(x) {}
#if IPHONE
#undef on_iphone
#undef on_ios
#undef on_ipad
#define on_iphone(x) if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {x}
#define on_ipad(x) if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {x}
#define on_ios(x) {x}
#define on_wide(x) if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {x}
#else
#undef on_mac
#define on_mac(x) {x}
#define on_wide(x) {x}
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment