0

I have a class where I have a private static constant:

class A {

    private static let MY_CONSTANT = 1000

    func setUp (xAxis:Charts.XAxis) {
        ...
    }
}

Also in this class I have a method (setUp), inside of that method I create another class which uses that constant:

func setUp (xAxis:Charts.XAxis) {

    class HistogramReadLenghtFormateer:IAxisValueFormatter {
        func stringForValue(_ value: Double, axis: AxisBase?) -> String {

            let lowIndex = Int(value) / A.MY_CONSTANT
            let topIndex = (Int(value) + A.MY_CONSTANT) / A.MY_CONSTANT
            return String(lowIndex) + "K" + "-" + String(topIndex) + "K"
        }
    }
    let histogramReadLenghtFormateer = HistogramReadLenghtFormateer()

    xAxis.labelPosition = .bottom
    xAxis.labelFont = .systemFont(ofSize: 6)
    xAxis.granularity = Double(A.MY_CONSTANT)
    xAxis.labelCount = 7
    xAxis.valueFormatter = histogramReadLenghtFormateer
}

Well, it seems that Xcode is ok with it, but AppCode complains:

Cannon Access to MY_CONSTANT. It is private in A

I know it's private but the class is defined inside of a method of the class A.

But it's even more intriguing that one compiler complain and the other one doesn't.

I guess it's because some settings of some kind. Any idea where to change this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
xarly
  • 2,054
  • 4
  • 24
  • 40
  • Looks like you are using `A.MY_CONSTANT` in a couple of places, which lines are generating the errors? Are they the ones from the inner class `HistogramReadLenghtFormateer`? – Cristik Jan 24 '19 at 15:07
  • Oh, sorry. The ones generate errors are inside of the class `HistogramReadLenghtFormateer` in the method `stringForValue` – xarly Jan 25 '19 at 17:05
  • 1
    Then it could be that the Swift compiler used by AppCode to not allow private declarations within a class to be visible in inner classes. Try switching to `fileprivate`, this might fix the visibility issue. – Cristik Jan 25 '19 at 17:08
  • Works fine for me. I'm using AppCode EAP 2019.1 with Xcode 10.1 – Jon Reid Feb 03 '19 at 05:23

1 Answers1

1

What you're seeing isn't a compiler error, it's part of AppCode's own analysis, which is wrong in this case. (Sorry about that, I've created an issue for you and will try to fix it soon.)

You should still be able to compile and run your project. If it doesn't, a different problem is causing it.

nschum
  • 15,322
  • 5
  • 58
  • 56