Thursday, July 24, 2008

ivar

import objc
help(objc.ivar)

gives this:
Help on class ivar in module __builtin__:

class ivar(object)
| ivar(name, type='@', isOutlet=False) -> instance-variable
|
| Creates a descriptor for accessing an Objective-C instance variable.
|
| This should only be used in the definition of Objective-C subclasses, and
| will then automaticly define the instance variable in the objective-C side.
|
| 'type' is optional and should be a signature string.
|
| The name is optional in class definitions and will default to the name the
| value is assigned to

So, as we might have expected, when we call ivar("x","i"), the i refers to the object's type (int). The reason all this is needed is that in Key-Value coding, accessor functions for an object named "x" should be named "x" and "getX." The name duplication is somehow OK in Objective C but not in Python, and objc.ivar somehow makes this work.

No comments: