3

In a class I have class variables, simulated by a struct with static members like this:

internal class DEAccountCheck : AccountCheck {

  private struct Static {
    static var methodParameters: [String: (UInt16, [UInt16])] = [ // Modulus + weights indexed by method id.
      "00": (10, [2, 1, 2, 1, 2, 1, 2, 1, 2]),
      "01": (10, [3, 7, 1, 3, 7, 1, 3, 7, 1]),
      "02": (11, [2, 3, 4, 5, 6, 7, 8, 9, 2]),
      "03": (10, [2, 1, 2, 1, 2, 1, 2, 1, 2]),
      ...
    ]
  }

There are more than 200 lines (entries) for the methodParameter dictionary. If I run my app I get an EXC_BAD_INSTRUCTION exception with the debugger stopping in the middle of my static initializer. I checked thereon when this starts to happen and found that I can have up to 172 values. One more and: puff.

As I can successfully add all entries by normal code the question arises if there's some known limit for static intializers.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • 1
    I think that you should [raise](https://bugreport.apple.com) this one as a bug with Apple. – Matt Gibson Dec 24 '14 at 16:20
  • This is a known bug - see these similar questions [1](http://stackoverflow.com/q/25810625/148357), [2](http://stackoverflow.com/q/25948024/148357) and [3](http://stackoverflow.com/q/26244263/148357) – Antonio Dec 25 '14 at 21:22
  • Well, the linked issues may have the same source like mine, but they are in fact different issues. Anyway, I guess a bug report is due. – Mike Lischke Dec 26 '14 at 09:02

1 Answers1

1

It turned out that the exception came from a duplicate key, which is not allowed. If the error messages in Swift would be more user friendly that problem would have been seen much easier. ATM error messages in Swift are simply terrible.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181