Collezione di Macro per iOS

      Nessun commento su Collezione di Macro per iOS

Di seguito elenco alcune macro utili durante lo sviluppo di applicazioni in Objective-C per iOS.

macro note

 

[code lang=”obj-c”]// Gradi a Radianti
#define degreesToRadians(x) (M_PI * x / 180.0)[/code]

[code lang=”obj-c”]// Invalidazione Timer
#define UA_invalidateTimer(t) [t invalidate]; t = nil;[/code]

[code lang=”obj-c”]
// Info Dispositivo
#define UA_isIPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UA_isIPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define UA_isRetinaDevice ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] >= 2)
#define UA_isMultiTaskingSupported ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [[UIDevice currentDevice] isMultitaskingSupported])[/code]

[code lang=”obj-c”]
// Threading
#define UA_runOnMainThread if (![NSThread isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self performSelector:_cmd]; }); return; };

[/code]

[code lang=”obj-c”]// Colori
#define UA_rgba(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define UA_rgb(r,g,b) UA_rgba(r, g, b, 1.0f)[/code]

[code lang=”obj-c”]
// Debugging / Logging
#ifdef DEBUG<
#define UA_log( s, … ) NSLog( @"<%@:%d> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define UA_log( s, … )
#endif
#define UA_logBounds(view) UA_log(@"%@ bounds: %@", view, NSStringFromRect([view bounds]))
#define UA_logFrame(view) UA_log(@"%@ frame: %@", view, NSStringFromRect([view frame]))[/code]

[code lang=”obj-c”]// Altro
#define NSStringFromBool(b) (b ? @"YES" : @"NO")
#define UA_SHOW_VIEW_BORDERS YES
#define UA_showDebugBorderForViewColor(view, color) if (UA_SHOW_VIEW_BORDERS) { view.layer.borderColor = color.CGColor; view.layer.borderWidth = 1.0; }
#define UA_showDebugBorderForView(view) UA_showDebugBorderForViewColor(view, [UIColor colorWithWhite:0.0 alpha:0.25])[/code]