2017-02-07 9 views
2

나는 CorePlot의 최신 버전을 사용하고, 나는이 오류로 실행 해요 :어떻게 NSDecimal 값 대신 NSNumber 값을 구현할 수 있습니까?

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

은 내가 이전 버전을 사용하는 튜토리얼에 내 응용 프로그램을 내놓고있어 때문에이 오류가 발생 실현 CorePlot. This changelog 상태 변화 중 하나 따라서

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