Search code examples
objective-cioscocoa-touchsubclassuiwindow

Subclassing UIWindow - Need Preprocessor Help


Yes, I know subclassing UIWindow is frowned upon, but my subclassed UIWindow is for debugging purposes only (it takes a screenshot of the current-page once a specific motion event is detected).

Anyway, I made a custom precompiler flag called DEBUG in my project's Build Settings, but I'm having a problem getting it to load/function properly. Right now, it's not taking the screenshot, but it is registering the occurrence of the motion event.

Here's the code I have in the AppDelegate's didFinishLaunchingWithOptions:

#if DEBUG
    DebugWindow *debugWindow = [[DebugWindow alloc] init];
    self.window = debugWindow; //'window' is declared in the AppDelegate's @interface file and synthesized as window=_window in the @implementation file  
#else
    self.window = _window;
#endif

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

Solution

  • Here is how to use debug flag

    #if DEBUG == 1
    #define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
    #define MARK    CMLog(@"%s", __PRETTY_FUNCTION__);
    #define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
    #define END_TIMER(msg)  NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
    #else
    #define CMLog(format, ...)
    #define MARK
    #define START_TIMER
    #define END_TIMER(msg)
    #endif
    

    And here is the screenshot

    enter image description here

    Also in the release setting put the flag to 0 Like this -DDEBUG=0

    This way you can achieve what you want to achieve.Let me know if it helps or not.