NSString initWithUTF8String - crazy retainCount with empty string
NSString initWithUTF8String - crazy retainCount with empty string
- Subject: NSString initWithUTF8String - crazy retainCount with empty string
- From: "Simon Strandgaard" <email@hidden>
- Date: Sat, 24 Mar 2007 16:33:39 +0100
I have asserts on retainCount a few places in my code,
and today I got surprised that with NSString sets a weird
retainCount when initialized with an empty string.
It looks like a bug to me?
I'm running XCode 2.4.1 on OSX 10.4.8.
So what's the safe way to get a NSString from a cstring?
--
Simon Strandgaard
http://opcoders.com/
---------------------------------------------------------------
#import <Cocoa/Cocoa.h>
int main(int argc, const char** argv)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
{
const char* s0 = "";
NSString* s1 = [[NSString alloc] initWithUTF8String: s0];
int rc = [s1 retainCount];
NSLog(@"rc = %i", rc);
// outputs "rc = 2147483647", which I don't understand !!
}
{
const char* s0 = "WHOAMI";
NSString* s1 = [[NSString alloc] initWithUTF8String: s0];
int rc = [s1 retainCount];
NSLog(@"rc = %i", rc);
// outputs "rc = 1" which is good
}
[pool release];
return 0;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden