Collezione di Macro per iOS

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

macro note

 

// Gradi a Radianti
 #define degreesToRadians(x) (M_PI * x / 180.0)
// Invalidazione Timer
 #define UA_invalidateTimer(t) [t invalidate]; t = nil;
// 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])
// Threading
 #define UA_runOnMainThread if (![NSThread isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self performSelector:_cmd]; }); return; };

// 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)
// 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]))
// 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])

Related Posts

Come creare un framework in swift

Programmare in Apple Swift 2

Swift: Come usare una classe Objective-C in Swift

Swift: UIWebView

Si prega di attivare i Javascript! / Please turn on Javascript!

Javaskripta ko calu karem! / Bitte schalten Sie Javascript!

S'il vous plaît activer Javascript! / Por favor, active Javascript!

Qing dakai JavaScript! / Qing dakai JavaScript!

Пожалуйста включите JavaScript! / Silakan aktifkan Javascript!