I need to concatenate some strings.
NSString * sportName = [[NSString alloc ]initWithString:@""];
sportName = [sportName stringByAppendingString:[someObject getString]];
// can be more stringByAppendingString
...
[sportName release];
But something strange for me give the ‘build and analyze’ command:
on string:
sportName = [sportName stringByAppendingString:[someObject getString]];
the error:
Method returns an Objective-C object with a +0 retain count (non-owning reference)
on string:
[sportName release];
the error:
Incorrect decrement of the reference count of an object that is not owned at this point by the caller
I am using it for filling my TableView and it is crashed after loading :(.
In 2nd line you are getting a new string which is assigned back to
spotName. So the alloced string in first line is leaked. I don’t understand why you need to append in an empty string. Appending to@""is practically of no effect. And if you have some non-empty string then you can create that as autoreleased string instead of alloc. Like this:And if you need to retain
spotNamethen you can retain that or use a property.