[Pyobjc-dev] kvc instance variables
Brought to you by:
ronaldoussoren
From: Chris M. <pyo...@mc...> - 2007-11-11 20:23:33
|
I'm going through chapter six now, and I'm running into issues with key value coding instance variables and how to create them. Using both approaches in the documentation I can't seem to find a way to create a NSString instance variable. I understand that I could just do myvar=NSString.new() or myvar=objc.ivar('myvar') and not give it the type, but neither of those seem to give me a full KVC instance variable of a certain type. From the NEWS.txt: - It is now conveniently possible to create instance variables with a specific type (e.g. without manually making up a encoded type string):: class MyObject (NSObject): bounds = objc.ivar.NSRect() done = objc.ivar.bool() From simple-kvo.py: class MyClass(NSObject): base = objc.ivar("base", objc._C_INT) power = objc.ivar("power", objc._C_INT) I'm looking to implement an instance variable of type NSString, but objc.ivar.NSString and objc._NSString do not exist for either approach. objc.ivar.NSRect and objc._C_INT appear as utilized above, but NSString seems to be missing. If you only import objc, you get just the basic types: In [1]: import objc In [2]: objc.ivar. #hit tab objc.ivar.__base__ objc.ivar.__bases__ objc.ivar.__basicsize__ objc.ivar.__call__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__cmp__ objc.ivar.__delattr__ objc.ivar.__delattr__ objc.ivar.__delattr__ objc.ivar.__delete__ objc.ivar.__dict__ objc.ivar.__dictoffset__ objc.ivar.__doc__ objc.ivar.__doc__ objc.ivar.__doc__ objc.ivar.__flags__ objc.ivar.__get__ objc.ivar.__getattribute__ objc.ivar.__getattribute__ objc.ivar.__getattribute__ objc.ivar.__hash__ objc.ivar.__hash__ objc.ivar.__hash__ objc.ivar.__init__ objc.ivar.__init__ objc.ivar.__init__ objc.ivar.__itemsize__ objc.ivar.__module__ objc.ivar.__mro__ objc.ivar.__name__ objc.ivar.__new__ objc.ivar.__new__ objc.ivar.__new__ objc.ivar.__reduce__ objc.ivar.__reduce__ objc.ivar.__reduce__ objc.ivar.__reduce_ex__ objc.ivar.__reduce_ex__ objc.ivar.__reduce_ex__ objc.ivar.__repr__ objc.ivar.__repr__ objc.ivar.__repr__ objc.ivar.__set__ objc.ivar.__setattr__ objc.ivar.__setattr__ objc.ivar.__setattr__ objc.ivar.__str__ objc.ivar.__str__ objc.ivar.__subclasses__ objc.ivar.__weakrefoffset__ objc.ivar.bool objc.ivar.char objc.ivar.double objc.ivar.float objc.ivar.int objc.ivar.long objc.ivar.long_long objc.ivar.mro objc.ivar.short objc.ivar.unsigned_char objc.ivar.unsigned_int objc.ivar.unsigned_long objc.ivar.unsigned_long_long objc.ivar.unsigned_short objc.ivar.__str__ Import Foundation and you get some more... but no NSString! Is there something else I need to import? In [2]: import Foundation In [3]: objc.ivar. #hit tab Display all 121 possibilities? (y or n) objc.ivar.__base__ objc.ivar.__bases__ objc.ivar.__basicsize__ objc.ivar.__call__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__class__ objc.ivar.__cmp__ objc.ivar.__delattr__ objc.ivar.__delattr__ objc.ivar.__delattr__ objc.ivar.__delete__ objc.ivar.__dict__ objc.ivar.__dictoffset__ objc.ivar.__doc__ objc.ivar.__doc__ objc.ivar.__doc__ objc.ivar.__flags__ objc.ivar.__get__ objc.ivar.__getattribute__ objc.ivar.__getattribute__ objc.ivar.__getattribute__ objc.ivar.__hash__ objc.ivar.__hash__ objc.ivar.__hash__ objc.ivar.__init__ objc.ivar.__init__ objc.ivar.__init__ objc.ivar.__itemsize__ objc.ivar.__module__ objc.ivar.__mro__ objc.ivar.__name__ objc.ivar.__new__ objc.ivar.__new__ objc.ivar.__new__ objc.ivar.__reduce__ objc.ivar.__reduce__ objc.ivar.__reduce__ objc.ivar.__reduce_ex__ objc.ivar.__reduce_ex__ objc.ivar.__reduce_ex__ objc.ivar.__repr__ objc.ivar.__repr__ objc.ivar.__repr__ objc.ivar.__set__ objc.ivar.__setattr__ objc.ivar.__setattr__ objc.ivar.__setattr__ objc.ivar.__str__ objc.ivar.__str__ objc.ivar.__subclasses__ objc.ivar.__weakrefoffset__ objc.ivar.bool objc.ivar.CFAllocatorContext objc.ivar.CFArrayCallBacks objc.ivar.CFBagCallBacks objc.ivar.CFBinaryHeapCallBacks objc.ivar.CFBinaryHeapCompareContext objc.ivar.CFDictionaryKeyCallBacks objc.ivar.CFDictionaryValueCallBacks objc.ivar.CFFileDescriptorContext objc.ivar.CFGregorianDate objc.ivar.CFGregorianUnits objc.ivar.CFMachPortContext objc.ivar.CFMessagePortContext objc.ivar.CFRange objc.ivar.CFRunLoopObserverContext objc.ivar.CFRunLoopSourceContext objc.ivar.CFRunLoopTimerContext objc.ivar.CFSetCallBacks objc.ivar.CFSocketContext objc.ivar.CFSocketSignature objc.ivar.CFStreamClientContext objc.ivar.CFStreamError objc.ivar.CFStringInlineBuffer objc.ivar.CFSwappedFloat32 objc.ivar.CFSwappedFloat64 objc.ivar.CFTreeContext objc.ivar.CFUUIDBytes objc.ivar.CFXMLAttributeDeclarationInfo objc.ivar.CFXMLAttributeListDeclarationInfo objc.ivar.CFXMLDocumentInfo objc.ivar.CFXMLDocumentTypeInfo objc.ivar.CFXMLElementInfo objc.ivar.CFXMLElementTypeDeclarationInfo objc.ivar.CFXMLEntityInfo objc.ivar.CFXMLEntityReferenceInfo objc.ivar.CFXMLExternalID objc.ivar.CFXMLNotationInfo objc.ivar.CFXMLParserCallBacks objc.ivar.CFXMLParserContext objc.ivar.CFXMLProcessingInstructionInfo objc.ivar.char objc.ivar.double objc.ivar.float objc.ivar.int objc.ivar.long objc.ivar.long_long objc.ivar.mro objc.ivar.NSAffineTransformStruct objc.ivar.NSDecimal objc.ivar.NSFastEnumerationState objc.ivar.NSHashEnumerator objc.ivar.NSHashTableCallBacks objc.ivar.NSMapEnumerator objc.ivar.NSMapTableKeyCallBacks objc.ivar.NSMapTableValueCallBacks objc.ivar.NSPoint objc.ivar.NSRange objc.ivar.NSRect objc.ivar.NSSize objc.ivar.NSSwappedDouble objc.ivar.NSSwappedFloat objc.ivar.short objc.ivar.unsigned_char objc.ivar.unsigned_int objc.ivar.unsigned_long objc.ivar.unsigned_long_long objc.ivar.unsigned_short objc.ivar.__str__ In [4]: objc.ivar.NSString --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /Volumes/Raid/mcclimans/Src/pyobjc-20x-branch/<ipython console> in <module>() AttributeError: type object 'ivar' has no attribute 'NSString' |