this is my first time asking something here, so don’t be too harsh on me please :-). I have a strange “bad access” issue. In a class of mine I have a NSInteger along with a few other members. I override the - (NSString *)description method to print the values of everything like so (omitted the unrelevant part):
- (NSString *)description {
return [NSString stringWithFormat:@"Duration:%d", duration];
}
and then I print that using NSLog(@"%@", myObject) which is giving me EXC_BAD_ACCESS without any log messages, regardless of the NSZombieEnabled.
- I have double checked the order of all formatting specifiers and
parameters – it’s correct. - I tried changing the format specifier to
%iand%@and didn’t get any result - When I init my object I don’t initialize
duration. Later, I assign it through a property@property NSInteger. So I tried initializing the duration to 0 in my
durationinit
method but to no avail. - If I box duration to a NSNumber prior to
printing, it works. - When I remove the duration and leave all the
other ivars it works again.
I’m stumped, what am I doing wrong here?
Can you help me?
Thanks a lot!
EDIT: To summarize, It seems this is caused by differences between 32 and 64 bit platforms, because it’s fine when run on an iphone 4 and has issues only when run in the simulator. I tried 3 different approaches – using %d and %i with the NSInteger variable itself, using %qi and using %ld/ %lx and I also tried to cast to int and long with the various format specifiers. Every time I can run on the device, but get EXC_BAD_ACCESS in the simulator.
The only guess here: NSInteger could be 64 bit in your case and %i (as well as %d) expects 32-bit integer, you can try %qi or (what seems to be better) cast the value explicitly.