在使用 NSParameterAssert 的任何地方,我都会遇到编译错误。例如:
-(instancetype)initForPlot:(CPTPlot *)plot withFunction:(CPTDataSourceFunction)function
{
NSParameterAssert([plot isKindOfClass:[CPTScatterPlot class]]);
NSParameterAssert(function);
if ( (self = [self initForPlot:plot]) ) {
dataSourceFunction = function;
}
return self;
}
该代码在 Xcode 6.2 中编译得很好,但是在 Xcode 6.3 中它给了我以下错误:
/Users/xxxx/Project/App/Presentation/CorePlot/Source/CPTFunctionDataSource.m:110:5: Using %s directive in NSString which is being passed as a formatting argument to the formatting method
我在网上查了一下,没有看到有关错误消息的信息。
我正在使用的临时修复如下:
#undef NSParameterAssert
#define NSParameterAssert(condition) ({\
do {\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Wcstring-format-directive\"")\
NSAssert((condition), @"Invalid parameter not satisfying: %s", #condition);\
_Pragma("clang diagnostic pop")\
} while(0);\
})
不过,应该有更好的解决方案。