Random Objective-C Question

Miscellaneous Forums/General Discussion/Random Objective-C Question


Ooh, one other thing - I found out that because of the ultra-slick messaging syntax in Objective-C, it isn't compulsary to cast objects down to a lower descendent to call a method/selector that isn't in the parent class - it automagically finds and calls it. ;-)


It's not necessary, but often prevents compiler warnings of the nature 'object may not respond to selector blah'.

And using (sometype*) to cast pointers in c/c++/objc doesn't incur any overhead (ie: it doesn't generate code), it's really just a way to telling the compiler that you (think you) know what you're doing.


But for some strange reason, there are a lot of places in cocoa.macos.m that handle each gadget separately and cast the gadget into the corresponding type before calling the exact same selector/method.


I'd recommend caution here: "initWithBytes:length:" and "initWithBytes:size:" are not the same selector, and I'm not 100% sure how objc even handles different param types (eg: ints vs floats) and how this affects selector selection(!).

But feel free to experiment anyway!