|
An Objective-C class in Cocoa has one hidden object that every knows about. The There is another hidden variable that very few seem to know about:
The most obvious application of
You would typically use it in a method like follows:
This logs a message to the console telling, what method, from what file, invoked with what object. Tremendously useful. Here's a second version that adds thread information:
This method returns an object in a dictionary where the key is the method name,
You could combine this with a property to get easy access inside a dictionary.
If you wanted a read-write property, you could implement it this way:
Now, we have a color property, without ever creating a color instance variable in the class. This has some advantages in that you don't have worry as much about memory management. The object is retained when it's added to SomeDictionary and released when SomeDictionary is released or when the object is replaced. The Objective-C runtime is full of neat little tricks and More advanced techniques can be used to implement some advanced functionality such as higher-order-messaging and even mimic methods as nearly first class objects. Functional programming aficionados can check out http://www.cocoadev.com/index.pl?HigherOrderMessaging for some discussion on this. |
about products blog contact misc xml
Copyright 2007-2009 6Tringle Inc