1.判斷橫豎屏
#define IsPortrait ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
2.截取系統(tǒng)時(shí)間戳
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]
3.是否高清屏
#define isRetina ([[UIScreen mainScreen] scale]== 2 ? YES : NO)
4.當(dāng)前系統(tǒng)設(shè)置國(guó)家的country iso code
#define countryISO [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]
5.當(dāng)前系統(tǒng)設(shè)置語(yǔ)言的 iso code
#define languageISO [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]
6.單例
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \\static classname *shared##classname = nil; \\+ (classname *)shared##classname \{ \@synchronized(self) \{ \if (shared##classname == nil) \{ \shared##classname = [[self alloc] init]; \} \} \\return shared##classname; \} \\+ (id)allocWithZone:(NSZone *)zone \{ \@synchronized(self) \{ \if (shared##classname == nil) \{ \shared##classname = [super allocWithZone:zone]; \return shared##classname; \} \
7.內(nèi)存方面宏
//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
//釋放一個(gè)對(duì)象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }
#define SAFE_RELEASE(x) [x release];x=nil