0

I added Charts through pods in a new project, and it compiles fine. But in the project where I actually need it, I get the attached errors during compilation. Swift Language is set to Swift 4.0 in Build Settings. Deployment Target is 9.0

There is currently no code using the Library, the error occurs after adding the Pod and trying to compile the existing project.

Are there any other settings I have to check regarding these errors?

enter image description here

@objc open lazy var rightYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: rightAxis, transformer: _rightAxisTransformer)

@objc open lazy var leftYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: leftAxis, transformer: _leftAxisTransformer)

@objc open lazy var xAxisRenderer = XAxisRenderer(viewPortHandler: _viewPortHandler, xAxis: _xAxis, transformer: _leftAxisTransformer)

Cannot use instance member '_viewPortHandler' within property initializer; property initializers run before 'self' is available

ChartUtils.drawText(context: context, text: value, point: CGPoint(x: xPos, y: yPos), align: align, attributes: [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: color])
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

Definition of variables

internal var _viewPortHandler: ViewPortHandler

@objc public init(viewPortHandler: ViewPortHandler)
{
   _viewPortHandler = viewPortHandler
}
Vario
  • 490
  • 4
  • 13
  • People can help you more effectively if you post a code snippet that demonstrates the error. – SaganRitual Mar 26 '18 at 06:56
  • i cannot post a code snipped, because the error occurs simply by adding the pod and trying to build. At this moment i have no code regarding the Charts library. I updated the questions to outline this state – Vario Mar 26 '18 at 07:54
  • I understand. Could you post the part of the code where `_viewPortHandler` is defined? – SaganRitual Mar 26 '18 at 08:41
  • Oh, I think this is it: https://stackoverflow.com/questions/43550813/property-initializers-run-before-self-is-available or more generally https://www.google.com/search?q=property+initializers+run+before+%27self%27+is+available&rlz=1C5CHFA_enUS688US688&oq=property+initializers+run+before+%27self%27+is+available&aqs=chrome..69i57j0.348j0j7&sourceid=chrome&ie=UTF-8 – SaganRitual Mar 26 '18 at 08:43
  • i added the definition above. What makes me curious is, that its ok in another project. – Vario Mar 26 '18 at 10:33
  • Did you look at [this](https://stackoverflow.com/questions/43550813/property-initializers-run-before-self-is-available) or [this](https://www.google.com/search?q=property+initializers+run+before+%27self%27+is+available&rlz=1C5CHFA_enUS688US688&oq=property+initializers+run+before+%27self%27+is+available&aqs=chrome..69i57j0.348j0j7&sourceid=chrome&ie=UTF-8)? – SaganRitual Mar 26 '18 at 13:03
  • have you used latest version of Charts ? – CodeChanger Mar 27 '18 at 07:18
  • yes i looked into this. Edit: my cocoapods repo did not update correctly. After dealing with some updates in cocoapods, i have now the latest charts 3.1.0, but the error is still the same, i got even more errors during the build – Vario Mar 27 '18 at 08:54
  • I think its not updating properly please try to remove and add again will work as above issue already solved new version. – CodeChanger Mar 27 '18 at 09:26
  • did you try cleaning the project and deleting derived data? – DevB2F Apr 04 '18 at 14:45
  • sorry for my delay, yes i tried and the problem still exists – Vario Apr 10 '18 at 08:57
  • I'm hitting this exact same error ... does anyone know the fix? – Dewey May 24 '18 at 21:24

1 Answers1

1

This process worked out for me

  1. Removed the Charts pod of older version (3.0.3).
  2. Installed the new version(3.1.x) of Charts through pods.
  3. Changed the Charts Swift Compiler language to 4.1 version enter image description here
Anvesh Tokala
  • 403
  • 4
  • 12