Key-Value coding with strange output


#1

I get “2961” as my output out of these codes:

-(void)awakeFromNib
{
    [self setValue:[NSNumber numberWithInt:10] forKey:@"ben"];
    NSNumber *b = [self valueForKey:@"ben"];
    NSString *text = [NSString stringWithFormat:@"%d",b];
    [labelView setStringValue:text];
}

first of all what is the problem? is it like the program returns the address of memory for the pointer?
second is it a good idea to write these type of assignments in “awakeFromNib” ?


#2

Hi,

I guess I can help with that:

Since NSNumber is no primitive type, but an object, you should use “%@” instead of “%d” for making a string with it.
I can only guess what the 2961 is, it might be an address, or some internal number the runtime gave the object.

As for your second question, awakeFromNib is the perfect place.

HTH,
spheenik