Charts: Swift 4.1 compilation warnings

Created on 8 Mar 2018  路  7Comments  路  Source: danielgindi/Charts

Bunch of warnings with version 3.0.5 of Charts and latest Swift 4.1 beta in Xcode 9.3 b4. Worth fixing because they're all very quick fixes and because some developers using -warnings-as-errors will see these as errors in their codebase.

Should also be an opportunity to remove the force unwraps and casts that are unnecessary. Most of these errors can be written using guard let or if let foo = foo instead.

/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/BarLineChartViewBase.swift:1692:66: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            return _data?.getDataSetByIndex(h!.dataSetIndex) as! IBarLineScatterCandleBubbleChartDataSet!
                                                                 ^                                      ~
                                                                                                        ?

/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:168:36: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        get { return (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled }
                                   ^                    ~
                                                        ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:169:29: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        set { (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled = newValue }
                            ^                    ~
                                                 ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:175:36: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        get { return (renderer as! CombinedChartRenderer!).drawBarShadowEnabled }
                                   ^                    ~
                                                        ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:176:29: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        set { (renderer as! CombinedChartRenderer!).drawBarShadowEnabled = newValue }
                            ^                    ~
                                                 ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:180:70: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
    open var isDrawValueAboveBarEnabled: Bool { return (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled }
                                                                     ^                    ~
                                                                                          ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:183:66: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
    open var isDrawBarShadowEnabled: Bool { return (renderer as! CombinedChartRenderer!).drawBarShadowEnabled }
                                                                 ^                    ~
                                                                                      ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:192:34: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            return (renderer as! CombinedChartRenderer!).drawOrder.map { $0.rawValue }
                                 ^                    ~
                                                      ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Charts/CombinedChartView.swift:196:27: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            (renderer as! CombinedChartRenderer!).drawOrder = newValue.map { DrawOrder(rawValue: $0)! }
                          ^                    ~
                                               ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Components/Legend.swift:170:34: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: font])
                                 ^       ~
                                         ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Components/Legend.swift:259:42: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                    let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont])
                                         ^       ~
                                                 ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Components/Legend.swift:346:57: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                    calculatedLabelSizes[i] = (label as NSString!).size(withAttributes: labelAttrs)
                                                        ^       ~
                                                                ?
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Filters/DataApproximator+N.swift:115:50: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
        let reducedEntries = points.enumerated().flatMap { (index: Int, point: CGPoint) -> CGPoint? in
                                                 ^
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Filters/DataApproximator+N.swift:115:50: note: use 'compactMap(_:)' instead
        let reducedEntries = points.enumerated().flatMap { (index: Int, point: CGPoint) -> CGPoint? in
                                                 ^~~~~~~
                                                 compactMap
/Users/alan/Downloads/Charts-3.0.5/Source/Charts/Renderers/LegendRenderer.swift:465:45: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                        posX -= (e.label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont]).width
                                            ^       ~
                                                    ?

All 7 comments

use master instead. Or wait 3.1 released.

Please re鈥搊pen. Master has the same issues. These are from building with master:

BarLineChartViewBase.swift:1692:66: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            return _data?.getDataSetByIndex(h!.dataSetIndex) as! IBarLineScatterCandleBubbleChartDataSet!
                                                                 ^                                      ~
                                                                                                        ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:168:36: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        get { return (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled }
                                   ^                    ~
                                                        ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:169:29: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        set { (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled = newValue }
                            ^                    ~
                                                 ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:175:36: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        get { return (renderer as! CombinedChartRenderer!).drawBarShadowEnabled }
                                   ^                    ~
                                                        ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:176:29: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
        set { (renderer as! CombinedChartRenderer!).drawBarShadowEnabled = newValue }
                            ^                    ~
                                                 ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:180:70: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
    open var isDrawValueAboveBarEnabled: Bool { return (renderer as! CombinedChartRenderer!).drawValueAboveBarEnabled }
                                                                     ^                    ~
                                                                                          ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:183:66: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
    open var isDrawBarShadowEnabled: Bool { return (renderer as! CombinedChartRenderer!).drawBarShadowEnabled }
                                                                 ^                    ~
                                                                                      ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:192:34: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            return (renderer as! CombinedChartRenderer!).drawOrder.map { $0.rawValue }
                                 ^                    ~
                                                      ?
/Users/alan/Downloads/Charts-master/Source/Charts/Charts/CombinedChartView.swift:196:27: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            (renderer as! CombinedChartRenderer!).drawOrder = newValue.map { DrawOrder(rawValue: $0)! }
                          ^                    ~
                                               ?
/Users/alan/Downloads/Charts-master/Source/Charts/Components/Legend.swift:170:34: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
            let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: font])
                                 ^       ~
                                         ?
/Users/alan/Downloads/Charts-master/Source/Charts/Components/Legend.swift:259:42: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                    let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont])
                                         ^       ~
                                                 ?
/Users/alan/Downloads/Charts-master/Source/Charts/Components/Legend.swift:346:57: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                    calculatedLabelSizes[i] = (label as NSString!).size(withAttributes: labelAttrs)
                                                        ^       ~
                                                                ?
/Users/alan/Downloads/Charts-master/Source/Charts/Filters/DataApproximator+N.swift:115:50: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
        let reducedEntries = points.enumerated().flatMap { (index: Int, point: CGPoint) -> CGPoint? in
                                                 ^
/Users/alan/Downloads/Charts-master/Source/Charts/Filters/DataApproximator+N.swift:115:50: note: use 'compactMap(_:)' instead
        let reducedEntries = points.enumerated().flatMap { (index: Int, point: CGPoint) -> CGPoint? in
                                                 ^~~~~~~
                                                 compactMap
/Users/alan/Downloads/Charts-master/Source/Charts/Renderers/LegendRenderer.swift:465:45: warning: using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead
                        posX -= (e.label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont]).width
                                            ^       ~
                                                    ?

don't use Version 9.3 beta
just Version 9.2 (9C40b)

Uh I鈥檓 giving you a heads up about the issue, obviously I don鈥檛 _have_ to use the beta.

Sometimes it鈥檚 smart to test your codebase (especially if you are in a large company) against Xcode betas so you can see potential sources of work ahead of time.

This is me doing you a courtesy by letting you know that your project needs work for the upcoming Swift version.

Xuan knows the problem but as long as it is a beta version he will not do anything he is waiting for the release version
it's normal the version is not stable

@alanzeino Thanks for the heads up. Generally we have a branch around that tracks these changes. I made it on my fork by accident this time, so it doesn't show up on the main Charts repo. We're ready for Swift 4.1. Don't worry ; )

oh, I must be drunk, I though swift 4.1 is an old version...
Yes don't worry once it's released, we will upgrade too.

Was this page helpful?
0 / 5 - 0 ratings