12

在使用 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);\
})

不过,应该有更好的解决方案。

4

1 回答 1

1

您所要做的就是将您的 core-plot 库更新到最新版本(对我有用),因为:

如果你去 Coreplot git repo ( https://github.com/core-plot/core-plot/commits/master ),

在提交中,您可以看到:

Commits on Feb 15, 2015
@eskroch
Fixed Xcode 6.3 beta build warnings.
eskroch authored on Feb 15

这意味着自 2 月 15 日以来,这个问题已经得到修复,比这个 iOS 8.3 版本早很长时间,因为它是 beta 版本。

于 2015-04-15T13:15:19.887 回答