我在这行代码中不断收到上述警告消息,但不知道如何更正它。
*err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"Decompression of %@ failed because we were unable to write to the destination data file at &@",sourcePath,destinationPath],
NSLocalizedDescriptionKey,
[outputStream streamError],
NSUnderlyingErrorKey,
nil]];
最佳答案
错误是拼写错误:“&@”而不是“%@”。
考虑像这样编写代码:
NSString *messageText = [NSString stringWithFormat:@"Decompression of %@ failed because we were unable to write to the destination data file at %@", sourcePath, destinationPath];
NSString *streamErrorText = [outputStream streamError];
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : messageText,
NSUnderlyingErrorKey : streamErrorText};
NSError *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:userInfo];
使用这种代码格式,错误会单独出现在一行中并且很容易找到。
编写代码供人们阅读,而不是编译器。
关于ios - 错误消息中的格式字符串未使用数据参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21096124/