Newbie warning: watch your NSLog data types
Newbie warning: watch your NSLog data types
- Subject: Newbie warning: watch your NSLog data types
- From: Scott Ellsworth <email@hidden>
- Date: Tue, 9 Aug 2005 11:30:45 -0700
Hi, all.
My code said
NSLog(@"\tExamining World: %@ - %@ - %@, WTN %f TM %f %@",
[neighborWorld valueForKey:@"name"],[neighborWorld
valueForKeyPath:@"sector.name"], [neighborWorld valueForKey:@"hex"],
[neighborWorld tradeRating], tradeModForNeighbor, @"end");
The log said:
2005-08-09 11:20:49.426 Astrogator[14065] Examining World:
Caliban - Core - 2218, WTN 0.000000 TM -0.000000 (null)
The code should have said:
NSLog(@"\tExamining World: %@ - %@ - %@, WTN %f TM %f %@",
[neighborWorld valueForKey:@"name"],[neighborWorld
valueForKeyPath:@"sector.name"], [neighborWorld valueForKey:@"hex"],
[[neighborWorld tradeRating] floatValue], tradeModForNeighbor, @"end");
The log would then have said:
2005-08-09 11:27:36.330 Astrogator[14161] Examining World:
Caliban - Core - 2218, WTN 0.000000 TM 10.800000 end
Obvious in retrospect: I had sent an NSNumber to something expecting
a float.
It would be very nice if there were an NSLog debug mode that did
(limited) type checking on arguments. I am still trying to figure
out how to write that - any 16 bits is a valid int16, which is not
easy to debug.
Scott
_______________________________________________
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