I’m trying to use the iOS Charts Plugin in my project, and have started by creating a NativeScript plugin, adding that dependency to a
platforms/ios, and then declaring the classes required to use the plugin in my code. The latest version of this Charts plugin is using Swift 4, and to get it building, I have set my
Podfile up as:
source 'https://github.com/CocoaPods/Specs.git' use_frameworks! platform :ios, '9' pod 'Charts' post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' end end end
And I have added the following to my
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
I have successfully been able to get the basic chart element working, which renders with no data, but the problem I’m facing is that it appears I can not add any data to the chart, because the TypeScript interface definition generated by NativeScript thinks that the
data property on the parent Chart class is
readonly, so when I attempt to assign data to it (as per every tutorial and bit of documentation I can find), e.g.;
barChartView.data = chartData;
I get the following error:
TypeError: Attempted to assign to readonly property.
I have generated the NativeScript type definitions to see what NativeScript is interpreting using:
TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios
From what I can see of the source Swift code, the
data getter/setter property is public, and the concrete class is exported to Objective-C - there are code examples in Objective-C using this plugin. All the other methods are visible in NativeScript (and useable), but many simple properties are appearing as
readonly when the TypeScript definition is generated.
At this stage I’m thinking maybe I have to create my own Swift/Objective-C wrapper to try get around this issue.
Has anyone come across this issue, or a similar one, and could recommend some solutions? And has anyone been able to get this Charts plugin working successfully with the most recent version and how did you do it?