ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.58k stars 6k forks source link

Xcode 9 / Swift 4 issue with current master #3152

Closed zoltansebestyen closed 6 years ago

zoltansebestyen commented 6 years ago

Hi,

I'm trying to use Charts in a project with Xcode 9 / Swift 4, but when building the project - no code yet, just skeleton with Pods - it fails with the errors below. I looked up the project issues, but couldn't find similar one, that's why I created a new one.

My Podfile looks like:

platform :ios, '8.0'
use_frameworks!

target 'OfxCharts' do
  pod "SwiftyXMLParser", :git => 'https://github.com/yahoojapan/SwiftyXMLParser.git'
  pod 'Charts', :git => 'https://github.com/danielgindi/Charts'
end

project 'OfxCharts.xcodeproj'

and I've got the following errors:

Swift Compiler Error Group
Swift Compiler Error Group
OfxCharts/Pods/Charts/Source/Charts/Charts/BarLineChartViewBase.swift:70:76: Cannot use instance member '_viewPortHandler' within property initializer; property initializers run before 'self' is available
OfxCharts/Pods/Charts/Source/Charts/Charts/BarLineChartViewBase.swift:74:77: Cannot use instance member '_viewPortHandler' within property initializer; property initializers run before 'self' is available
OfxCharts/Pods/Charts/Source/Charts/Charts/BarLineChartViewBase.swift:81:72: Cannot use instance member '_viewPortHandler' within property initializer; property initializers run before 'self' is available
OfxCharts/Pods/Charts/Source/Charts/Renderers/BarChartRenderer.swift:611:121: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
OfxCharts/Pods/ObjectiveC.NSObject:160:15: Did you mean 'zone'?
OfxCharts/Pods/ObjectiveC.NSObject:162:21: Did you mean 'zone'?
OfxCharts/Pods/Charts/Source/Charts/Renderers/BubbleChartRenderer.swift:190:38: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
OfxCharts/Pods/ObjectiveC.NSObject:160:15: Did you mean 'zone'?
OfxCharts/Pods/ObjectiveC.NSObject:162:21: Did you mean 'zone'?
OfxCharts/Pods/Charts/Source/Charts/Renderers/CandleStickChartRenderer.swift:306:42: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
OfxCharts/Pods/ObjectiveC.NSObject:160:15: Did you mean 'zone'?
OfxCharts/Pods/ObjectiveC.NSObject:162:21: Did you mean 'zone'?
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:153:33: Incorrect argument label in call (have 'withAttributes:', expected 'attributes:')
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:157:33: Incorrect argument label in call (have 'withAttributes:', expected 'attributes:')
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:162:60: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:175:33: Incorrect argument label in call (have 'withAttributes:', expected 'attributes:')
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:196:69: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:204:37: Incorrect argument label in call (have 'withAttributes:', expected 'attributes:')
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:213:69: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:246:95: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:261:95: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Utils/ChartUtils.swift:269:109: Cannot convert value of type '[NSAttributedStringKey : Any]?' (aka 'Optional<Dictionary<NSString, Any>>') to expected argument type '[String : Any]?'
OfxCharts/Pods/Charts/Source/Charts/Charts/ChartViewBase.swift:317:18: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
OfxCharts/Pods/ObjectiveC.NSObject:160:15: Did you mean 'zone'?
OfxCharts/Pods/ObjectiveC.NSObject:162:21: Did you mean 'zone'?
OfxCharts/Pods/Charts/Source/Charts/Charts/ChartViewBase.swift:349:15: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
OfxCharts/Pods/ObjectiveC.NSObject:160:15: Did you mean 'zone'?
OfxCharts/Pods/ObjectiveC.NSObject:162:21: Did you mean 'zone'?
OfxCharts/Pods/Charts/Source/Charts/Charts/ChartViewBase.swift:350:15: Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

Do you have some suggestion to resolve the issue?

Thanks,

Zoltan

jjatie commented 6 years ago

That's not the latest version of Charts. All of these errors are correct in 3.0.4. I'm guessing you need to update your cocoa pods.

zoltansebestyen commented 6 years ago

Are you sure? I cleaned up my local cocapods installation (rm -fr ~/.cocoapods/repos/master; pod setup), explicitly set Charts version to '3.0.4', and still getting the same errors. Actually pod install after the cocoapod update stated that Installing Charts 3.0.4 (was 3.0.4).

liuxuan30 commented 6 years ago

I remember that 3.0.4 does not address some syntax change for swift 4.0.3. Try master?

jjatie commented 6 years ago

If that's the case we should really push an update to the pod. Cloning the repo, there are no issues.

zoltansebestyen commented 6 years ago

Ok, sorted out: I had to set Swift language version to 4.0 for Charts at Pods->Charts->Build Settings->Swift Language Version. Setting Swift language version to 4.0 at project level wasn't enough. :/

liuxuan30 commented 6 years ago

@jjatie you mean we push current master into pod? master is kind of WIP, but should be fine.

jjatie commented 6 years ago

@liuxuan30 Yea. Let's get the last few More Swift into Master PRs done, bump the version to 3.0.5, and push the master to pod.

lukewcn commented 6 years ago

3.0.5 got the same error either

liuxuan30 commented 6 years ago

can't be. I already pushed:

      - 3.0.4 (2017-09-22 03:08:18 UTC)
      - 3.0.5 (2018-01-08 02:33:37 UTC)
zoltansebestyen commented 6 years ago

For the record: the original root cause was Swift version not set to 4.0, see my earlier comment