[Pyobjc-dev] How to do isKindOfClass:? (and a bug fix)
Brought to you by:
ronaldoussoren
|
From: Bill B. <bb...@co...> - 2002-10-16 21:28:50
|
The NSStringFromClass() function in Foundation was misnamed as
NSClassFromString() -- breaking the original implementation of that
function. Fixed.
I added a propertyListFromPythonCollection() function to the
Foundation. It is just a copy/paste of what was previously committed
in the example.
I was going to go ahead and write the obvious
pythonCollectionFromPropertyList() function, but ran into a problem.
[bumbox:~/bbum-developer/sourceforge/pyobjc] 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 *
>>> mD = NSMutableDictionary.dictionary()
>>> mD
<NSCFDictionary objective-c instance 0x161cf0>
>>> mD.__class__
<objective-c class NSCFDictionary at 0x8db130>
>>> mD.isKindOfClass_(NSClassFromString("NSDictionary"))
0
>>> NSClassFromString("NSDictionary")
<objective-c class NSDictionary at 0x82f3b0>
>>> mD.isKindOfClass_("NSDictionary")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: expected a ObjC class or None for argument 1: its typespec
is '#'
>>> mD.isKindOfClass_(NSDictionary)
0
>>> NSDictionary
<objective-c class NSDictionary at 0x82f3b0>
(If you are running the unpatched version of PyObjC, you'll need to use
lookup_class, not NSClassFromString()).
b.bum
|