Re: [Pyobjc-dev] Re: [Pythonmac-SIG] pyobjc / cocoa
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-10-17 20:18:43
|
On Thursday, Oct 17, 2002, at 20:29 Europe/Amsterdam, Bill Bumgarner wrote: > On Thursday, October 17, 2002, at 02:01 PM, Bob Ippolito wrote: >> IMHO there should also be easy to use wrappers for NSNumber and >> NSData.. I use those on a pretty regular basis for stuff that needs >> to get serialized for DO or plists. I'd prefer not to special case Objective-C classes in the extension module. We currently do so for NSString and NSNumber, and I'd prefer to not add other exceptions. > > Wrapping NSNumber and NSData is definitely on the radar, but there is > some subtlety in how they need to be wrapped. I totally agree that > they should be wrapped in some fashion. > > On the ObjC->Python front, do you mean: > > [bumbox:~] bbum% python > Python 2.2 (#1, 07/14/02, 23:25:09) > [GCC Apple cpp-precomp 6.14] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> from Foundation import * > >>> a = NSMutableArray.array() > >>> d = NSMutableDictionary.dictionary() > >>> a.addObject_("a") > >>> a[0] > 'a' > >>> d['foo'] = 'bar' > >>> d['baz'] = 'bob' > >>> d.keys() > ['baz', 'foo'] > >>> d.description() > '{baz = bob; foo = bar; }' > >>> d.objectForKey_('baz') > 'bob' > >>> d['baz'] > 'bob' > > Already in there -- just not quite complete. The current mechanism is a bit of a hack: the 'objc' module maintains a list of methods that are added if a selector is present in the objective-C class (e.g. if the class has 'objectForKey:' add an __getitem__ method that calls objectForKey_). This should work for most collection classes. > >> Does pyobjc do garbage collection? I'd imagine that you could have >> the __init__ for anything to a retain and the __del__ for anything do >> a release without getting in the way.. Pyobjc tries very hard to maintain correct retainCounts on the Objective-C object. In general it should not be necessary to think about this. Please tell the list if you do have to call 'retain' or 'release', upto now I've been able to find a generic solution for every instance where I had to take care of retainCounts in Python code. Ronald |