The delegate support is achieved by a objc_delegate() function that converts a Python object to the corresponded Objective C delegate instance. A list of protocols intended to conform are also passed to the objc_delegate() function.
The objc_delegate() dynamically creates a new Objective C class inherited by NSObject, then adds desired protocols methods and instantiates the instance. The instance is converted to Python object before returned so it can be passed to other MetaObjcClass methods that requires delegate instance.
In order to achieve dynamic implementation of protocol methods. A `delegate_register` dict is added to remember the class name and corresponded Python object. So the dynamic function can dispatch the call to real Python object's method. However, currently registered delegates won't get released. Still looking for a way to free unused objects.
This commit also adds an example at exampls/delegate.py. However, because the protocol method will be called asynchronously. I needs to write the example as a simple Kivy app so the execution won't quit before the protocol instance gets called. There may be a simpler way to implement a event loop but I failed.
There is another problem about dynamically creating an Objective C class. That is, we need to use the objc_getProtocol() runtime function to find interested protocol methods (for signature and types). However, it seems not all protocols can be found through this function. More information about this issue can be found here: http://goo.gl/zA116F
Signed-off-by: Olli Wang <olliwang@ollix.com>