Re: [Pyobjc-dev] DictType -> ObjC
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-10-18 15:06:58
|
On Thursday, Oct 17, 2002, at 22:58 Europe/Amsterdam, Bill Bumgarner wrote: > On Thursday, October 17, 2002, at 04:32 PM, Jack Jansen wrote: >> On donderdag, oktober 17, 2002, at 01:12 , Bill Bumgarner wrote: >>> How hard would it be to proxy DictType, ArrayType, and TupleType >>> into Obj-C such that they look/feel/act/behave/are subclasses of >>> NSDictionary and NSArray? >> >> Will these objects still be compatible with CoreFoundation? I'm not >> familiar enough with how Apple made CF and NS objects >> interchangeable, but if Pyobjc would handle most objects not by >> actually converting them but by putting them in something that merely >> "looks/feels/acts/behaves" like the real NS class that may not be >> good enough. I assume that "are" is good enough, but again I'm not >> sure. > > Yes -- it is simply a matter of implementing the appropriate primitive > methods for each class [for class clusters]: [removed example] Great. Actually adding these collection proxies is fairly trivial. With a just commited version of python: from Foundation import NSMutableArray a = NSMutableArray.alloc().init() a.addObject_(1) a.addObject_({'hello':'world'}) a.addObject_([3, 4, 5]) print "The array:", type(a), a print "a[0]:", type(a[0]), `a[0]` print "a[1]:", type(a[1]), `a[1]` print "a[2]:", type(a[2]), `a[2]` Gives: The array: <objective-c class NSCFArray at 0x30ed70> (1, {hello = world; }, (3, 4, 5)) a[0]: <objective-c class NSCFNumber at 0x2d7550> 1 a[1]: <type 'dict'> {'hello': 'world'} a[2]: <type 'list'> [3, 4, 5] Note that a[1] and a[2] are printed like NSDictionary and NSArray objects while in the NSMutableArray. Ronald |