swift - Why am I getting 'fatal error: Array index out of range' with this code? -


i have following constants class declared such. whenever outside class callsconstants.drawingtypes or constants.colorflags, following error:

fatal error: array index out of range

i'm afraid might misunderstanding static keyword, intent of methods , members of class arrange set of constants , arrays of used in application.

is there obvious error i'm missing here, in declarations or otherwise?

import foundation  class constants {       enum drawingtypes: string, printable {         case = "any"         case line = "line"         case cubicbezier = "cubic bezier"         case squarebezier = "square bezier"         case linefilled = "line filled"         case cubicfilled = "cubic filled"         case squarebezierfilled = "square bezier filled"         case multilayer = "multilayer"          var description: string { return rawvalue }     }      enum colorflags : string, printable     {         case darks = "darks"         case pastels = "pastels"         case fullrange = "full range"         case greys = "greys"          var description : string {return rawvalue }     }      static let allcolorflags = [colorflags.darks,                                 colorflags.pastels,                                 colorflags.fullrange,                                 colorflags.greys]      static let alldrawingtypes = [drawingtypes.any,                                  drawingtypes.line,                                 drawingtypes.cubicbezier,                                 drawingtypes.squarebezier,                                 drawingtypes.linefilled,                                 drawingtypes.cubicfilled,                                 drawingtypes.squarebezierfilled,                                 drawingtypes.multilayer]       class func randomtypeincludingmulti() -> drawingtypes {         return randomtype(true)     }      class func randomtype(includingmulti : bool) -> drawingtypes {         let min = 1         var max = constants.alldrawingtypes.count          if includingmulti == false             { max = max - 1 }          let = int(arc4random_uniform(uint32(max - min))) + min         return constants.alldrawingtypes[i]     }      class func randomcolorflag() -> colorflags {         let min = 0         let max = constants.allcolorflags.count         let = int(arc4random_uniform(uint32(max - min))) + min         return constants.allcolorflags[i]     }  } 

edit :

enter image description here

after debugging more, noticed following happens on line 65 (only sometimes!)

return constants.alldrawingtypes[i] 

when method goes find indexed item, upon return, values max, min , i reset somehow, how error occurs. (you can see values in debug area). clearly, constants.alldrawingtypes[-1074625864] going throw exception. question is, why values being reset after going static array? i'm thinking not understanding statics correctly...


Comments

Popular posts from this blog

python - How to create jsonb index using GIN on SQLAlchemy? -

PHP DOM loadHTML() method unusual warning -

c# - TransactionScope not rolling back although no complete() is called -