我遇到了一个奇怪的语义问题:
在消息发送表达式的开头缺少'[‘
还有一个解析问题:
预期的“]”
在NSLog行的AFURLConnectionOperation.m中
@catch(NSException *e) { caughtException = e; }
if(caughtException) {
NSLog(NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil), NSStringFromClass([self class]), caughtException, [caughtException userInfo]);
}
[exceptionPool drain];在我加入之后
#define NSLog(__FORMAT__, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)到我项目的预编译文件:Proj-Prefix.pch
如何纠正此错误?
我搜索了,但除了注释NSLog行之外,没有任何解决办法。
提前感谢!
编辑:
NSLog(@"%@", [NSString stringWithFormat:NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil), NSStringFromClass([self class]), caughtException, [caughtException userInfo]]);和
NSLog(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", NSStringFromClass([self class]), caughtException, [caughtException userInfo]);都没问题。
,但为什么原始的没有? :?
发布于 2012-04-28 04:59:20
考虑一下宏观扩张。在宏中,您试图使用字符串文本连接:
(@"%s [Line %d] " __FORMAT__)但是__FORMAT__参数的值是NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil),它不是字符串文本。扩张的方式如下:
(@"%s [Line %d] " NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil))显然这是错误的语法。由于NSLocalizedString本身是一个宏(在NSBundle.h中定义),所以这个错误是无法理解的,所以整个展开如下所示:
(@"%s [Line %d] " [[NSBundle mainBundle] localizedStringForKey:(@"Unhandled exception on %@ networking thread: %@, userInfo: %@") value:@"" table:nil])顺便说一下,您不应该使用__FORMAT__作为宏参数名。以两个下划线开头的所有标识符都是保留的。(还保留了所有以下划线开头的标识符,后面跟着大写字母。)
https://stackoverflow.com/questions/10360085
复制相似问题