[Pyobjc-dev] class vs. instance attributes for IBOutlets
Brought to you by:
ronaldoussoren
|
From: Joe S. <jo...@st...> - 2008-10-12 14:12:35
|
I'm re-learning Python, and learning Cocoa and PyObjC all at the same
time. So maybe this is silly question:
The examples I've seen have the IBOutlets (and often data too) defined
at the class level, like so:
class ToDoListAppDelegate(NSObject):
toDoTableView = objc.IBOutlet()
newItemField = objc.IBOutlet()
toDoList = []
But it occurred to me last night that this would be a problem in an
NSObject class that might have more than one instance -- wouldn't
apply to the app delegate, of course, but it could apply to a window
controller. So I moved the toDoList (which is a mutable type) to the
init function. Then, on a lark, I found I could move the IBOutlets
there too, so it looks like this:
class ToDoListAppDelegate(NSObject):
def init(self):
NSLog(u"init")
self.toDoTableView = objc.IBOutlet()
self.newItemField = objc.IBOutlet()
self = super(ToDoListAppDelegate, self).init()
if self is not None: self.toDoList = []
return self
So here's my question: is this necessary for IBOutlets (in a non-
singleton class of course)? Or is it not necessary, perhaps because
this is an immutable type? And what's the standard best practice for
these things?
Thanks,
- Joe
|