我有一个应该返回 NSURL 的函数,但我不小心让它返回了 NSString。 Xcode 没有发出任何警告。知道为什么会这样或者我如何为此启用警告。 (这会导致应用程序稍后崩溃)。顺便说一句,如果我更改函数以返回 NSMutableDictionary,我确实会收到有关不兼容返回类型的编译器警告。我使用的是 Xcode 4.5.1。
-(NSURL *) urlForThing:(Thing *)thing
{
//This is clearly a string at compile time and I would expect a warning
//If I change this to [NSMutableDictionary alloc] I do get a warning
return [NSString stringWithFormat:@"thing://url/%@", thing];
}
最佳答案
嗯,我想简短的答案是 stringWithFormat:
返回一个 id
,而不是 NSString
。这对我来说没有多大意义,但它解释了缺乏警告的原因。
关于objective-c - 返回 NSString 而不是 NSURL 不会引起警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13081785/