2017-02-07 3 views
2

私はCorePlotの最新バージョンを使用している、と私は、このエラーに実行している:私はの古いバージョンを使用してチュートリアルに私のアプリを基づかてるのでNSDecimal値の代わりにNSNumber値を実装するにはどうすればよいですか?

Sending 'NSDecimal' to parameter of incompatible type 'NSNumber * _Nonnull'

私はこのエラーが発生することを実現CorePlot。 This changelogの状態変化の1:

Changed all public properties and methods that take NSDecimal values to take NSNumber values instead. In some cases, the NSDecimal version of the method remains and a new version that takes NSNumber values was added.

Swift does not support NSDecimal values. Using NSNumber values instead has several advantages. Swift automatically bridges numeric values to NSNumber as needed. This also reduces the need to use the NSDecimal wrapper functions, e.g., CPTDecimalFromDouble() to convert values in Objective-C. When greater precision is required for a particular value, use NSDecimalNumber to maintain full decimal precision.

はこのように、私は私のエラーが原因で発生し知っているが、私はそれを修正する方法がわかりません。何か案は?ここに私のコードです:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    CPTGraphHostingView* hostView = [[CPTGraphHostingView alloc] initWithFrame:self.view.frame]; 
    [self.view addSubview: hostView]; 

    CPTGraph* graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds]; 
    hostView.hostedGraph = graph; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace; 

    [plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(16)]]; 
    [plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-4) length:CPTDecimalFromFloat(8)]]; 

    CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero]; 

    plot.dataSource = self; 

    [graph addPlot:plot toPlotSpace:graph.defaultPlotSpace]; 
} 

答えて

2

使用NSNumberオブジェクトの代わりに、NSDecimals:

[plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:@0 length:@16]]; 
[plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:@-4 length:@8]]; 

あなたがNSNumberNSDecimalを変換する必要がある場合は、あなたが使用することができNSDecimalNumber

NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithDecimal:someDecimal]; 
+0

これは、まさに私が探していたもの! – fi12

関連する問題