Forum Archive

objc_util access `super`

lukaskollmer

Hi,

I'm creating a subclass of UITextView using create_new_class.

This subclass implements a couple of methods specific to UITextView.

How can I access/call super in these methods?

dgelessus

This looks like something that objc_util doesn't natively support. The relevant declarations from Apple's Objective-C Runtime Reference are:

struct objc_super {
    id receiver; // Object to which to send the message
    Class class; // Superclass whose implementation should be used
};

id objc_msgSendSuper(struct objc_super *super, SEL op, ...);
void objc_msgSendSuper_stret(struct objc_super *super, SEL op, ...);
JonB

you should be able to copy the from ObjCInstanceMethod, and change the objc_class line:

class ObjCInstanceMethodSuperclass (object):
    '''Wrapper for an Objective-C instance method. ObjCInstance generates these objects automatically when accessing an attribute, you typically don't need to use this class directly.'''
    def __init__(self, obj, method_name, allow_property=True):
        self.obj = obj
        objc_class = obj.superclass() #modified!!
                ......

then create one manually.