From the Python point of view, you access Objective-C objects (both classes and instances) using a Python wrapper around them, ObjCObject. It is responsible of forwarding any unknown method you execute on it to the Objective-C object it is carrying.
ObjCObject objects have the following methods.
To send a message to an Objective-C object you use the same syntax as for any other Python object:
>>> import ObjC >>> List = ObjC.runtime.List >>> list = List() >>> Object = ObjC.runtime.Object >>> instance = Object() >>> list.addObject__ (instance)
Due to the different calling syntax though the Objective-C selectors name change slightly: the expression ``[obj someMethod:argA with:argB]'' becomes ``obj.someMethod__with__ (argA, argB)'' once coded in Python. The rule to follow is very simple: take the concise notation of the selector (the example above gives ``someMethod:with:'') and replace every colon (':') character with a double underscore ('__'), then feed the arguments as usual. As you may notice, the name of selectors without arguments does not change at all.
An alternative translation scheme was introduced with version 0.45 of the module: first replace every underscore in the name with a triple one ('___'), then replace every colon with a single underscore. Since underscores are not common in Objective-C method names, this gives shorter names.
Since allowing this double syntax introduces a little speed penality, I plan to remove one of the alternatives in the final 1.0 release.
The notation ``list.addObject__'' does actually return a ObjCMethod instance, described below, that you may cache as any other method. For example:
>>> import ObjC >>> List = ObjC.runtime.List >>> list_alloc = List.alloc >>> instance = list_alloc().init()
When an ObjCObject represent a Objective-C class, you can ``call'' it as you normally do with Python classes: it is a shortcut for a longer ``.alloc().init()''. You can pass initialization arguments to the call: if the Objective-C class instance responds to a method called ``init:::...'' that method is called feeding it the arguments as usual. Alternatively, you may specify the right selector to be used to initialize the object by using the init keyword parameter, in this way:
>>> import ObjC >>> List = ObjC.runtime.List >>> list = List(10, init='initCount:')
If the wrapped Objective-C object implements the methods -length (or -count) and -objectAt: (or -objectAtIndex:) than it's possible to treat it as any other sequence object, thus giving:
>>> list = ObjC.runtime.List() >>> list.addObject__ ('spam') >>> list.addObject__ (1) >>> list.addObject__ ('liter') >>> list.addObject__ ('please) >>> print list.count() 4 >>> print list.capacity() 7 >>> print list[:] ['spam', 1, 'liter', 'please'] >>> print list+list ['spam', 1, 'liter', 'please', 'spam', 1, 'liter', 'please'] >>> print list*3 ['spam', 1, 'liter', 'please', 'spam', 1, 'liter', 'please', 'spam', 1, 'liter', 'please'] >>> for i in list: print i ... spam 1 liter please
Otherwise, if it implements the methods -length (or -count) and -valueForKey: (or -objectForKey:) than it's possible to treat it as any other mapping object.