Reputation: 31
I have the following dictionary of arrays:
var Levels = [1:[0,3,1,1,3,2,0,9,5,4,3,1,0,9,8,2],2:[5,2,9,1,3,2,0,8,5,4,3,1,0,9,8,6],3:[5,2,7,1,3,2,0,4,5,4,3,3,0,9,8,3],4:[2,5,1,2,6,2,0,9,5,4,3,1,0,9,8,1]] //...and so on, up to ~900
Each array is different from the last. I have about 1000 of these generated, and I did consider using generation within the program, but also thought it may cause the user to experience lag waiting for a new level to load. It's a number puzzle, and pretty simple in terms of coding, but this large dictionary has been slowing down Xcode and causing the indexing to go nuts. I get this error now that I've never seen before when trying to build:
Command failed due to signal: Segmentation fault 11
Is there a better way to arrange about 1000 arrays like this? How should I set that up? I need to reference a key or something too, instead of using individual variables for each level. Thanks!! - GG
Upvotes: 0
Views: 699
Reputation: 3863
If you have 1000 arrays, why don't you put then in a property list file/files and read them in at runtime? Do you really need all of that level data in memory at all times?
if let
path = NSBundle.mainBundle().pathForResource("Level1-10", ofType: "plist"),
dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
level1 = dict["1"] as? Array<Int> {
// Use level1 array here
}
Upvotes: 2
Reputation: 535138
The Swift compiler doesn't like huge literals. You will have to assemble this value in code. (In the early days, I was able to get the same issue just by writing a single expression concatenating a dozen literal strings. The solution was to write a dozen string variables and concatenate those.)
You can file a bug report, and probably should, but it will probably come back as a duplicate, since I'm fairly sure Apple knows about this.
Upvotes: 3