Showing posts with label APPLE. Show all posts
Showing posts with label APPLE. Show all posts

Friday, August 29, 2014

A Macro to Dump CGRect

Recently, I worked on a class derived from UIScrollView.  In order to dump the CGRect's conveniently, I mean better than NSStringFromCGRect(), I introduced the following macro:

#ifdef DEBUG
    #define DBG(format, ...)                NSLog(@"%d,%s,"format,__LINE__,__FUNCTION__,##__VA_ARGS__);
    #define DUMP_RECT(rect)                 DBG("\n"                   \
                                                #rect"\n"              \
                                                "....x:|%.0f|\n"       \
                                                "....y:|%.0f|\n"       \
                                                "....width:|%.0f|\n"   \
                                                "....height:|%.0f|\n", \
                                                rect.origin.x,         \
                                                rect.origin.y,         \
                                                rect.size.width,       \
                                                rect.size.height)
#else
    #define DBG(format, ...)
    #define DUMP_RECT(rect)
#endif

Note the stringizing operator (#) operator to dump the "rect". Its sample use in LPTSCrollView class:

- (void)reset
{
...
    DUMP_RECT(self.frame)
    DUMP_RECT(self.bounds)
...
}

Its sample outputs:

2014-08-29 16:15:03.829 PhotonPro[18253:60b] 98,-[LPTScrollView reset],
self.frame
....x:|0|
....y:|0|
....width:|320|
....height:|568|
2014-08-29 16:15:03.830 PhotonPro[18253:60b] 100,-[LPTScrollView reset],
self.bounds
....x:|0|
....y:|0|
....width:|320|
....height:|568|

Hopefully, it will help somebody!


Thursday, January 19, 2012

How to Set the "tintColor" of the Back Button for Popovers in iOS5

I am developing an iPad application. After customizing the popover background by setting it red, I tried to set the "tintColor" of the "Back" button on the popover navigation bar. Otherwise, it looks ugly!



As I am developing the application in iOS5, the new appearance protocol makes customization very easy:


- (void)customizeAppearance
{
    // set the back button tint color
    [[UIBarButtonItem appearance] setTintColor: [UIColor redColor]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
    DBG_CALLED
    
    [self customizeAppearance];

    return YES;
}

Note that DBG_CALLED is my debug macro. However, in this case the update is global and the buttons on the toolbar are updated also which is not what I want!




The solution is specifying where to update the bar button items:


- (void)customizeAppearance
{
    // set the back button tint color for the popovers
    [[UIBarButtonItem appearanceWhenContainedIn:[UIPopoverController class], nil] 
                                   setTintColor:[UIColor redColor]];
}

The end result is what I want exactly:


I love the iOS5!


Monday, February 16, 2009

A Debug Macro for Xcode

* Updated on 28 November 2011 for Xcode 4.2

I am a newcomer to the Xcode and I decided to check the debug means. Basically, I was looking for a macro to dump line number, file name and function name along with some output. However, I found only some "simple" debug classes. I think debug output should be done by macros. I checked the Apple documentation and found an interesting topic: Variadic Macros. They are introduced by the C99 standard. After a few attempts I decided that the following macro is good enough for me:

//
//  dbg.h
//
//  Created by oguz.kupusoglu@gmail.com on 15/2/2009.
//  Copyright 2009 Oguz Kupusoglu. All rights reserved.
//

#ifdef DEBUG
    #define DBG(format, ...)                   NSLog(@"%d,%s,"format,__LINE__,__FUNCTION__,##__VA_ARGS__);
    #define DBG_CALLED                         DBG("called")
#else
    #define DBG(format, ...)
    #define DBG_CALLED
#endif

#define LOG(format, ...)                       NSLog(@"%d,%s,"format,__LINE__,__FUNCTION__,##__VA_ARGS__);
#define LOG_CALLED                             LOG("called")   

Note that DBG_CALLED is a helper define which is useful for following the callstack. I ignored the file name, i.e. __FILE__, as the method name being in the [class method] format gives a hint of the file in question due to naming files after the class names convention. Certainly one can add __FILE__ at the expense of extra overhead. Sample usage and output as received from the Console which is accessed from the "View/Debug Area/Activate Console" option of the Xcode are below:

-(void) viewWillAppear:(BOOL)animated
{
    DBG_CALLED
    
    DBG("view frame\n"
        "origin x:|%.0f|  y:|%.0f|\n"
        "width:|%.0f|  height:|%.0f|\n",
        self.view.frame.origin.x, self.view.frame.origin.y,
        self.view.frame.size.width, self.view.frame.size.height)   
       
    DBG("year:|%d|", 2009)
   
    DBG("updated")
       
    [super viewWillAppear:animated];
}

...] 69,-[MyViewController viewWillAppear:],called
...] 75,-[MyViewController  viewWillAppear:],view frame
origin x:|0|  y:|20|
width:|768|  height:|1004|
...] 77,-[MyViewController viewWillAppear:],year:|2009|
...] 79,-[MyViewController viewWillAppear:],updated

Note that the DEBUG define is set via the "PROJECT/Build Settings" option. Go to "... Preprocessing" section and add the define "DEBUG" to the "Debug" subsection.

Finally, I think "Product/Generate Output\Generate Preprocessed File" is a good option as it gives the preprocessor output of the selected file. For example the above DBG() macros are expanded as below:

-(void) viewWillAppear:(BOOL)animated
{
    NSLog(@"%d,%s,""called",69,__FUNCTION__);

    NSLog(@"%d,%s,""view frame\n" "origin x:|%.0f|  y:|%.0f|\n" "width:|%.0f|  height:|%.0f|\n",75,__FUNCTION__, self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);





    NSLog(@"%d,%s,""year:|%d|",77,__FUNCTION__, 2009);

    NSLog(@"%d,%s,""updated",79,__FUNCTION__);

    [super viewWillAppear:animated];
}

Note that when there is no variable argument, "##" removes the trailing comma! Just excellent...

Sunday, February 8, 2009

Introduction to MacBook

I bought a MacBook On 28 January 2009 from the Pupa at IstinyePark. My first impression is that it is very well designed! I think the Apple Key, i.e. "cmd" key, replaces the Control Key on the Windows computers. And, there is no "right" mouse key: in order to open a context menu the user needs to press "cntrl" key. However, I think having no "fullscreen" windows is a problem! Plus, it is not easy to see the open windows: F3 keys shows them and CMD+TAB selects windows sequentially. Overall I think as time goes by I will like the MacBook!