Hacker News new | ask | show | jobs
by mpweiher 4913 days ago
You generally try to make tests positive, which then makes this work ( -isEqual: rather than -isDifferent:).

Of course, there is one place where you have to go the other way: -isNil: does not work, you need to use -isNotNil

Unless you use the runtime's (private) nil-hook:

    +(void)setNilHandler
    {
        installed=YES;
        _objc_setNilReceiver([self nsNil]);
    }
Then you can send messages to nil and they will be sent to your class. Of course, you want to mimic the nil-eating behavior as much as possible, so:

    static id idresult( id receiver, SEL selector, ... )  { return nil; }

    +(BOOL)resolveInstanceMethod:(SEL)selector
    {
        class_addMethod(self, selector, (IMP)idresult , "@@:@");
        return YES;
    }