Skip to content

Core Plot API Changes Between Versions 1.x and 2.x

Eric Skroch edited this page Oct 3, 2015 · 2 revisions

The Core Plot API changed for version 2.0 in several ways that will require updates for client code written against the 1.x API. The following changes were made to simplify using Core Plot with Swift and to implement new Xcode 7 features that improve both Swift and Objective-C client code.

  • 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.

  • Renamed the CPTXYAxis.orthogonalCoordinateDecimal property to CPTXYAxis.orthogonalPosition.

    The name change for this property reflects the change in type from NSDecimal to NSNumber.

  • Added plot space point conversion methods that take an NSArray of coordinate values.

    It is difficult to use the conversion methods that take c-style arrays of double or NSDecimal values from Swift. The new methods (see list below) are also simpler to use from Objective-C, especially when the plot point values are already encoded as NSNumber values.

      -plotAreaViewPointForPlotPoint:
      -plotPointForEvent:
      -plotPointForPlotAreaViewPoint:
    
  • Added nullability annotations to all property and method declarations.

    This eliminates Swift optionals where they aren't needed and gives the compilers (both Swift and Objective-C) the ability to warn when client code attempts to pass nil values to methods that require non-nil values.

  • Added type annotations to all arrays, sets, and dictionaries.

    This provides clarity in both Swift and Objective-C about what types should be in various collections. It allows the compiler to make sure Core Plot receives the types it expects in collections, reducing runtime problems.

Clone this wiki locally