Dear iPhone Developers,
I have an instance method which is meant to return a string
- (NSString *)newFile:(NSString *)inFile andFileNumber:(NSInteger)aNumber {
return [NSString stringWithFormat:@"%@.o%i",inFile,aNumber];
}
I call this method as
outputFileName = [self newFile:inputFileName andFileNumber:newNumber];
// where inputFileName is a string and newNumber is an integer
// outputFileName (also a string), inputFileName and newNumber are declared in
// the interface and in the implementation
When I compile the project with Analyzer, it gives the following messages;
- Method returns an Objective-C object with a +0 retain count (non-owning reference)
- Object returned to caller with a +0 (non-owning) retain count
- Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected
Also when it tries to release outputFileName the application crashes. Does somebody has any clue what is going wrong? Thanks in advance.
The problem is an assumption of convention. Specifically, the static analyzer assumes that any method that starts with
newreturns a retained object. This is because the system APIs follow this convention.Rename your method;
fileNameWithBase:fileNumber:comes to mind.