Bug in NSLog; program to verify included.
Bug in NSLog; program to verify included.
- Subject: Bug in NSLog; program to verify included.
- From: tyler <email@hidden>
- Date: Sun, 15 Jul 2001 11:05:17 -0700
Hi,
I've found a potential bug in NSLog (I think). I'm new to Cocoa
programming, but this looks pretty straight forward. Using PB 1.0.1 and
OS X 10.0.3; project is simple "Foundation Tool" with only the below
code included.
NSNumber objects in a NSMutableDictionary seem to cause NSLog() to throw
an exception.
Sample code and output demonstrating the problem are included below.
With indicated line uncommented (adding of NSNumber to dictionary) the
following output occurs:
Output:
Jul 15 10:56:32 Learning1.1[382] *** -[NSCFString objCType]: selector
not recognized
Jul 15 10:56:32 Learning1.1[382] *** Uncaught exception:
<NSInvalidArgumentException> *** -[NSCFString objCType]: selector not
recognized
With the indicated line commented out the output is as follows:
Output:
Dictionary d description: {1 = "yup!"; question1 = "Can you believe
it?"; }
Sample Program:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *d;
d = [[NSMutableDictionary alloc] init];
// add a simple object
[d setObject: @"Can you believe it?" forKey: @"question1"];
// Try to add a number object
// If this next line is uncommented, it makes NSLog throw an
exception.
// [d setObject: @"nope!" forKey: [NSNumber numberWithLong: 1]];
// this works (adding stringValue method call to convert to string)
[d setObject: @"yup!" forKey: [[NSNumber numberWithLong: 1]
stringValue]];
// here is where the exception is thrown if the commented out line
// above is uncommented and compiled in.
NSLog(@"Dictionary d description: %@\n", d );
[d release];
[pool release];
return 0;
}