Re: [Pyobjc-dev] re: NSObject-derived class initialization
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-07-16 05:19:03
|
On Wednesday, 16 July, 2003, at 00:21, Sean Gilbertson wrote: > Hello all, > > If I missed this on some FAQ, sorry. > > I am wondering if there is some preferred way of handling > initialization of NSObject-derived Python classes in PyObjC? I am > fine with calling "object.alloc( ).init( )," is there a way to have a > "def init( self )" sort of function, that could call a super method at > the end? It would be nice if __init__ was still called, but I can see > how arguments could be made to the contrary. The methodname doesn't have underscores when using PyObjC, otherwise it is almost a normal initialiser. The init method must return self, and must call the superclass implementation of init (or technicly the 'designated initialiser' of the superclass). The following pattern should be used for initialisers: def init(self): self = super(MyClass, self).init() # Initialize this instance return self The primairy reason for not using __init__ is that the init method must be called explicitly for ObjC objects, have two different, yet simular, initialisers would be confusing. Ronald |