语义问题:缺少“[”的消息的发送开始表达
问题描述:
我得到一个奇怪的语义问题:语义问题:缺少“[”的消息的发送开始表达
失踪“[”的消息的发送开始表达
和解析的问题:
预期 ']'
在NSLog
线AFURLConnectionOperation.m
:我添加
#define NSLog(__FORMAT__, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
到我的项目的预编译的文件
@catch(NSException *e) { caughtException = e; }
if(caughtException) {
NSLog(NSLocalizedString(@"Unhandled exception on %@ networking thread: %@, userInfo: %@", nil), NSStringFromClass([self class]), caughtException, [caughtException userInfo]);
}
[exceptionPool drain];
后: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]);
都还好。
但是为什么原来的那个不?:?
答
想想宏观扩张。在您的宏,你想使用字符串字面串联:
(@"%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__
作为宏参数名称。所有以两个下划线开头的标识符都是保留的。 (也保留所有以下划线开头且后跟大写字母的标识符。)
Thanks @rob!这真的太棒了! (这个宏由TestFlight建议)顺便说一句,我发现你的答案大部分都很棒!你天才! ;) – Kjuly 2012-04-28 05:21:48