working on a mac os project (meaning not iPhone) requiring 10.6 and is 64bit, allows me to use properties to generate both accessor methods and instance variables in the header file. but, during debug, i'm not seeing how to look at the object's properties values after they have been populated. is there some build setting that needs to be turned on?
if i am declaring an object's instance variables (between {} in the header), then i can see those values (when they are used) during debug either in the debug window itself, or by using the cursor-hover over the highlighted line trick in the editor during a break, or by doing cli in gdb like 'p *object' for instance.
old way:
@class Suit;
@interface Card : NSObject
{
NSNumber *playOrder;
Suit *suit;
NSNumber *displayNumber;
NSNumber *orderIndex;
}
@property(nonatomic, retain) Suit *suit;
@property(nonatomic, retain) NSNumber *displayNumber;
@property(nonatomic, retain) NSNumber *orderIndex;
new way:
@class Suit;
@interface Card : NSObject
@property(nonatomic, retain) Suit *suit;
@property(nonatomic, retain) NSNumber *displayNumber;
@property(nonatomic, retain) NSNumber *orderIndex;
@property(nonatomic, retain) NSNumber *playOrder;
in this new-fangled 10.6 required 64bit idea (which seems simpler to me) none of these debug methods display the object's values. i figure that i must have something turned off, because this newer idea, doesn't seem better.
gdb results for old way:
(gdb) po newCard
New Card : 0 of Suit : Hearts (NSCalibratedRGBColorSpace 1 0 0 1). with orderIndex of: 1
(gdb) p *newCard
$1 = {
<NSObject> = {
isa = 0x100002188
},
members of Card:
playOrder = 0x0,
suit = 0x200053a20,
displayNumber = 0x20001bac0,
orderIndex = 0x200012de0
}
(gdb)
gdb results for new way:
(gdb) po newCard
New Card : 0 of Suit : Hearts (NSCalibratedRGBColorSpace 1 0 0 1). with orderIndex of: 1
(gdb) p *newCard
$3 = {
<NSObject> = {
isa = 0x100002188
}, <No data fields>}
(gdb)
so looking at the docs for objective-c 2.0:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW3
describes what i am referring to (synthesizing instance variables in 'modern' runtime), but what isn't said anywhere, is that if you do this, the values will not be available during debugging.
i've found开发者_运维技巧 an SO page with pertinent information, but not focused on this effect: Using instance variables with Modern Runtime
what did i miss?
In GDB, you can use property getters to access dynamic ivars:
(gdb) po [newCard displayNumber] 0
I assume that you are @synthesizing
those variables?
You may also need { }
in the interface, so the compiler knows where to put it.
@interface Card : NSObject
{
}
I would avoid this kind of syntax... especially if you define the properties yourself.
Also, look up <objc/runtime.h>
and see if you can print a list of ivars for the class. I use the following all the time for debugging methods or classes from APIs that have no documentation.
unsigned int total_method_count = 0;
Method * method_list = class_copyMethodList(object_getClass([obj class]), &total_method_count);
@try
{
int method_counter = 0;
for (method_counter = 0; method_counter < total_method_count; method_counter++)
{
Method method = method_list[method_counter];
// check if method the KVC getter you are interested in
NSLog(@"Method: %s", sel_getName(method_getName(method)));
}
} @catch (NSException *e) {
//Do Nothing
}
I had the same problem with synthesized ivars. My solution was to switch to the LLVM 1.6 compiler in XCode 3.25. This brought back debugger tooltips (most helpful to me), but the variables window still fails to show the ivars.
精彩评论