2014-11-04 64 views
1

我有一个日志功能NSInteger的警告:删除使用__LINE__

#define LOGERROR(err) if(err) {      \ 
    LOGTRACE(@"[NSError] %s (%d): (%d:%@) Reason: %@", \ 
     __PRETTY_FUNCTION__,       \ 
     __LINE__,          \ 
     err.code,          \ 
     err.domain,          \ 
     err.localizedDescription)      \ 
} 

当我把它与

LOGERROR(playerItem.error); 

我得到一个警告:“NSInteger的不应该被用来作为一个格式化参数,加明确演员长“。

Xcode的autofix在LOGERROR之前插入%ld,这是错误的。

我觉得这个警告来自使用__LINE__,它根据https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html返回一个int。

如何从此通话中删除警告?

+1

我认为它实际上对'err.code'感到恼火,它返回一个'NSInteger'。投它:'(long)(err.code)',然后在格式字符串中使用'%ld'。 – ravron 2014-11-04 19:17:08

+0

啊,谢谢,就是这样。只是误解了它。 – quantumpotato 2014-11-04 19:22:30

回答

1

刚刚正式我评论答曰:

编译器抱怨使用err.code,它返回一个NSInteger。将其转换为long(long)(err.code),然后在格式字符串中使用%ld