Skip to content

Instantly share code, notes, and snippets.

@jon
Created December 17, 2010 21:50
Show Gist options
  • Save jon/745763 to your computer and use it in GitHub Desktop.
Save jon/745763 to your computer and use it in GitHub Desktop.
//
// Prefix header for all source files of the 'Folio' target in the 'Folio' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CoreText/CoreText.h>
#import "NSOperationQueue+CommonQueue.h"
#import "UIApplication+CommonDirectoryExtensions.h"
#import "BPMainThreadNotificationQueue.h"
#import "NSObject+BPMainThreadNotificationQueue.h"
#import "BPUUID.h"
#define A(obj, objs...) [NSArray arrayWithObjects:obj, ## objs , nil]
#define F(a) [a objectAtIndex:0]
#define I(a, i) [a objectAtIndex:i]
#define R(a) [a subarrayWithRange:NSMakeRange(1, [a length] - 1)]
#define D(value, key, values...) [NSDictionary dictionaryWithObjectsAndKeys:value, key, ## values , nil]
#define V(o, k) [o objectForKey:k]
#define S(v) [v description]
// Number boxing and unboxing macros
#define Bb(i) [NSNumber numberWithBool:i]
#define Bc(i) [NSNumber numberWithChar:i]
#define Bs(i) [NSNumber numberWithShort:i]
#define Bi(i) [NSNumber numberWithInteger:i]
#define Bl(i) [NSNumber numberWithLong:i]
#define Bll(i) [NSNumber numberWithLongLong:i]
#define Bf(i) [NSNumber numberWithFloat:i]
#define Bd(i) [NSNumber numberWithDouble:i]
#define Ub(n) [n boolValue]
#define Uc(n) [n charValue]
#define Us(n) [n shortValue]
#define Ui(n) [n integerValue]
#define Ul(n) [n longValue]
#define Ull(n) [n longLongValue]
#define Uf(n) [n floatValue]
#define Ud(n) [n doubleValue]
#define iPhone() [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone
#define iPad() [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad
static uint32_t iOSCurrentVersion() {
NSString *versionString = [[UIDevice currentDevice] systemVersion];
NSArray *versionComponents = [versionString componentsSeparatedByString:@"."];
if ([versionComponents count] > 4)
versionComponents = [versionComponents subarrayWithRange:NSMakeRange(0, 4)];
uint32_t bits = 24;
uint32_t accum = 0;
for (NSString *component in versionComponents) {
accum |= [component integerValue] << bits;
bits -= 8;
}
return accum;
}
#define iOS(major, minor, tiny) ((major << 24) | (minor << 16) | (tiny << 8))
#define Scale() ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0)
#ifdef DEBUG
#define DebugLog(fmt, args...) NSLog(fmt, ## args)
#else
#define DebugLog(fmt, args...) do { } while (0)
#endif
#define NilIfEmpty(s) (([s length] > 0) ? s : nil)
#define NotificationObservationSupport static NSMutableArray *_observedNotificationNames = nil
#define ObserveNotification(notificationName, aSelector) do { if (_observedNotificationNames == nil) _observedNotificationNames = [NSMutableArray new]; [[NSNotificationCenter defaultCenter] addObserver:self selector:aSelector name:notificationName object:nil]; [_observedNotificationNames addObject:notificationName]; } while (0)
#define CleanupNotificationObservers do { for (NSString *notificationName in _observedNotificationNames) { [[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:nil]; [_observedNotificationNames removeObject:notificationName]; } [_observedNotificationNames release]; _observedNotificationNames = nil; } while (0)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment