Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4.1 compilation warnings #3323

Closed
alanzeino opened this issue Mar 8, 2018 · 7 comments
Closed

Swift 4.1 compilation warnings #3323

alanzeino opened this issue Mar 8, 2018 · 7 comments

Comments

@alanzeino
Copy link

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
                                            ^       ~
                                                    ?
@liuxuan30
Copy link
Member

use master instead. Or wait 3.1 released.

@alanzeino
Copy link
Author

Please re–open. 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
                                            ^       ~
                                                    ?

@thierryH91200
Copy link
Contributor

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

@alanzeino
Copy link
Author

Uh I’m giving you a heads up about the issue, obviously I don’t have to use the beta.

Sometimes it’s 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.

@thierryH91200
Copy link
Contributor

thierryH91200 commented Mar 10, 2018

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

@jjatie
Copy link
Collaborator

jjatie commented Mar 10, 2018

@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 ; )

@liuxuan30
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants