- (NSString*)instanceMethod

UCU*_*110 1 iphone objective-c ios4

亲爱的iPhone开发者,我有一个实例方法,意味着返回一个字符串

- (NSString *)newFile:(NSString *)inFile andFileNumber:(NSInteger)aNumber {
    return [NSString stringWithFormat:@"%@.o%i",inFile,aNumber];
}
Run Code Online (Sandbox Code Playgroud)

我将此方法称为

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
Run Code Online (Sandbox Code Playgroud)

当我使用Analyzer编译项目时,它会提供以下消息;

  1. 方法返回一个带有+0保留计数的Objective-C对象(非拥有引用)
  2. 对象以+0(非拥有)保留计数返回给调用者
  3. 具有+0保留计数的对象返回给调用者,其中预期+1(拥有)保留计数

此外,当它尝试释放outputFileName时,应用程序崩溃.有人知道出了什么问题吗?提前致谢.

bbu*_*bum 8

问题是惯例的假设.具体来说,静态分析器假定任何以start开头的方法都new返回一个保留的对象.这是因为系统API遵循此约定.

重命名你的方法; fileNameWithBase:fileNumber:浮现在脑海中.