Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

On Objective-C and Faggots

Name: Anonymous 2009-11-22 11:45

So this faggot iPhone developer has been bitching to me about how C++ is a shitty language and how Objective-C is the greatest thing on the planet. How can I get back at him?

Name: Anonymous 2009-11-22 22:51

>>20
I'd rather not post code from my work, but for a callback that takes three arguments, here's what it might look like:

    // call target selector with a, b, c
    assert(target);
    assert(sel);
    NSMethodSignature* signature = [[target class] instanceMethodSignatureForSelector:sel];
    assert([signature numberOfArguments] == 3);
    NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
    [invocation setTarget:target];
    [invocation setArgument:&a atIndex:2];
    [invocation setArgument:&b atIndex:3];
    [invocation setArgument:&c atIndex:4];
    [invocation invoke];
}


So yeah, calling selectors is such bullshit it feels like a  joke by the language designers. NSObject has performSelector:withObject:withObject: and friends as a workaround, but that only helps if your callback has two arguments or less; usually one argument is the source object, so that doesn't give you much room for a rich callback function. Have fun writing the above for every callback. You can of course template it as a helper, if you like building your entire codebase as Objective-C++...

In general, I feel like this in Objective-C *all the time*. This is just one example of many, many things that are made far more difficult than they should be. Things that should be brain-dead simple are actually huge blocks of code.

Newer Posts