There is some code that I am using written by someone else that I have a question….
NSString *c = @"test"; // "Local" string
NSString *d = [NSString alloc]initWithString:@"test"]; // "Heap" string
const char *c = "test";
return [NSString stringWithUTF8String:c]; // ??
I am not sure what the return statement in this case is returning. I would have written it something like…
return [NSString alloc]initWithUTF8String:c];
or
return [NSString alloc]initWithUTF8String:c]autorelease];
Why would the return statement be written like above?
[NSString stringWithUTF8String:c]returns an autoreleased object ..so its the same thing as[NSString alloc]initWithUTF8String:c]autorelease]but from what i understand from documentation[NSString stringWithUTF8String:c]doesn’t make a copy of the string..so its faster