Window controllers, code obfuscation

  • Hi, I'm trying to decipher someone else's code who is no longer
    available.  He did something that I think I can simplify, but I first
    want to make sure I'm not being completely wrong-headed about what I'm
    looking at.

    He does the following in his MyDocument.m file:

    - (void)windowControllerDidLoadNib:(NSWindowController *)aController
    {

    NSWindow* window = [[[self windowControllers] objectAtIndex:0] window];
    [[window windowController] setShouldCascadeWindows:NO];

    .
    .
    .
    }

    In English:

    He grabs a reference to the array of window controllers from the
    document object.
    He grabs the first window controller from that array.
    He grabs the window from that window controller.
    He sends a message, setShouldCascadeWindows:NO, to that window's
    window controller.

    Unless I'm being completely stupid about this, he could have done this, right?

    [[[self windowControllers] objectAtIndex:0] setShouldCascadeWindows:NO];


    Or better yet, this?

    [aController setShouldCascadeWindows:NO];

    Thanks,
    -s
  • On 19 Aug 2008, at 5:20 pm, Sumner Trammell wrote:

    > Hi, I'm trying to decipher someone else's code who is no longer
    > available.  He did something that I think I can simplify, but I first
    > want to make sure I'm not being completely wrong-headed about what I'm
    > looking at.

    First off, does this person's code not work? If it does, my advice is
    to leave it alone. Debugged code, no matter how bizarre-looking, is
    better than any amount of theoretically excellent code that might not
    work.

    So, with that out of the way:

    > Or better yet, this?
    >
    > [aController setShouldCascadeWindows:NO];

    This seems the most straightforward thing to do. The question you need
    to answer to your own satisfaction is: Is this what the original coder
    intended? Is it functionally equivalent to the original code?

    hth,

    Graham
  • --- On Tue, 8/19/08, Sumner Trammell <sumner.trammell...> wrote:

    > Unless I'm being completely stupid about this, he could
    > have done this, right?
    >
    > [[[self windowControllers] objectAtIndex:0]
    > setShouldCascadeWindows:NO];
    >
    >
    > Or better yet, this?
    >
    > [aController setShouldCascadeWindows:NO];

    Unless there's some really odd, ill-advised NSWindow subclass/category at work here, yes. It looks like maybe this method was originally meant to do something different, and the second line just got changed rather than rewriting the first to be more idiomatic.

    Cheers,
    Chuck
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today