Am 25.05.2008 um 09:41 schrieb Jens Alfke:
* Calling any method on a NULL object pointer doesn't crash, and doesn't call any code; instead, it's a no-op. This is actually extremely useful and can be taken advantage of to make your code much more concise by eliminating a lot of pointer checks.

One warning: For methods that have a return value, only certain return types are supported (which will in that case return 0). So read up on the details if you want to send a message to NIL.

* Method dispatch is more dynamic; it's based on the name of the method (the selector) not a vtable offset. This means that even if you don't know the class of an object at compile time, you can still call methods on it. For example, given a declaration "id foo", you can call [foo doSomething] and it will successfully call a method named doSomething, if foo has a base class that implements it, no matter what the class hierarchy looks like.

This is why ObjC supports "duck typing". Great tool in the tool belt.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to