Return values of user-defined Objective-C classes
indoxan last edited by
Hi, I'm trying to define a class method in
objc_utilthat returns my customized UI class as follows:
from objc_util import * def myButton(_cls, _cmd): cls = ObjCInstance(_cls) button = cls.alloc().init().autorelease() # customize the button ... return button MyButton = create_objc_class( "MyButton", ObjCClass("UIButton"), classmethods=[myButton]) if __name__ == "__main__": my_button = MyButton.myButton() ...
But the return value is
I tried to set the return value to
button.ptr, but it had no effect.
I also took into account the
restypeissues, but they were a bit too technical for me.
What is the correct way?
cvp last edited by cvp
@indoxan Not what you want, but I think (not sure) that you need first to create an instance of your class.
from objc_util import * def myButton(_self, _cmd): button = ObjCInstance(_self) # customize the button button.opaque = True MyButton = create_objc_class( "MyButton", ObjCClass("UIButton"), methods=[myButton], protocols=) if __name__ == "__main__": my_button = MyButton.alloc().init() print(my_button) my_button.myButton() print(my_button)
indoxan last edited by indoxan
Thanks for the reply, @cvp.
I'm implementing the
myButtonmethod as a class method, so I don't think creating an instance is necessary.
I wanted to define a class method that returns a customized instance, like
But this story should be put aside for now. As you say, similar things seem to be happen even when defining them as regular methods.