Casting anonymous Objects leads to different values on getter functions (while getting no warnings at compile time)
Casting anonymous Objects leads to different values on getter functions (while getting no warnings at compile time)
- Subject: Casting anonymous Objects leads to different values on getter functions (while getting no warnings at compile time)
- From: Martin Wilz <email@hidden>
- Date: Fri, 4 Nov 2005 14:09:22 +0100
Hi,
After spending some hours finding a bug, I thought I'd drop a mail to
this list to get some
background knowledge about the cause for this problem. Otherwise I'd
like to check your
opinions on filing a bug report.
The shortened story so far (the long story involves me and my
colleague first suspecting wrong bindings and/or archiving to be the
cause of the problems but I'm sure you don't want to know about that):
I've two objects, one contains an array with objects of the other kind.
@implementation VideoQualityConfig
-(id) init
{
self = [super init];
width = 369;
return self;
}
- (int) width
{
NSLog(@"width => %d", width);
return width;
}
@end
@implementation Config
- (id) init
{
self = [super init];
configurations = [[NSMutableArray alloc] init];
return self;
}
- (int) widthForConfigurationAtIndex:(int) index
{
return [[configurations objectAtIndex:index] width];
}
- (NSMutableArray *) configurations
{
return configurations;
}
@end
Depending how I access the value for width, I get differing results:
[config widthForConfigurationAtIndex:index]
and
[[[config configurations] objectAtIndex:index] width]
both seem to get me random values with every run while only (notice
the type cast)
[(VideoQualityConfig*) [[config configurations] objectAtIndex:0] width]
gives the value stored in the VideoQualityConfig object.
Somehow there seems to be confusion with other objects implementing the width
method (e.g. NSTableColumn). The NSLog in my -width method - however -
shows that my method is called; it just does not return the correct
value.
I''ve seen conflicts like this before, but there were always warnings
while compiling, that led me to cause of the problem. Not in this case
(what I consider to be a bug in Xcode as I don't want to research
other objects using the same method names as I do nor do I want to use
Namespace for my method names to avoid collision...)
Now I'd like to know about the mechanics behind this behaviour and I'm
sure there's somebody on this list willing to share his knowledge. If
this topic has been discussed before I'd be happy to be pointed to it.
(Unfortunately the search terms I came up with were to general to find
anything meaningful.)
You may download a ready to compile sample project for reconstruction
of the problem at :
http://wilz.de/download/Themen/Anfang/CastingTest.zip
Martin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden