0

I am build a simple Swift app that requires a small 'cube' of data; based on a dog breed (index 11) and the region of the country (index 0), I have to read 10 Ints. I have done this as an array of arrays. (See below)

When the application is running, everything works as expected.

HOWEVER, when Xcode is building, the indexing takes many minutes/never finishes, this is not only a pain as it delays the change/build/test cycle but it also keeps all of the autocomplete and type ahead from completing. The more rows that I add the slower it seems to get and I have more rows to add...

Just commenting out the one var allows the type ahead to work, but of course it will not compile as the the compiler is looking for that data structure to be there.

1) Is there a better way to store the data (I have not gotten into Coredata or databases (yet)?

2) Is this an Xcode bug that needs to be reported to Apple?

I have tried the cleaning of the project and derived files with no success.

var akcTable = [
    [ 1, 2, 2, 4, 6, 6,10,16,18,28,35, "Spaniels (English Springer)"],
    [ 2, 2, 2, 4, 5, 7, 8, 9,13,17,20, "Spaniels (English Springer)"],
    [ 3, 2, 2, 3, 4, 4, 7, 7, 9,12,14, "Spaniels (English Springer)"],
    [ 4, 2, 2, 4, 4, 6, 6,11,14,20,28, "Spaniels (English Springer)"],
    [ 5, 2, 2, 3, 4, 5, 7, 6, 9,10,12, "Spaniels (English Springer)"],
    [ 6, 2, 2, 4, 4, 6, 6, 8,11,11,17, "Spaniels (English Springer)"],
    [ 7, 2, 2, 4, 5, 5, 7, 6, 9, 9,14, "Spaniels (English Springer)"],
    [ 8, 2, 2, 5, 7, 7,11,11,15,18,22, "Spaniels (English Springer)"],
    [ 9, 2, 2, 4, 5, 6, 7, 8,12,13,20, "Spaniels (English Springer)"],
    [10, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Spaniels (English Springer)"],
    [11, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Spaniels (English Springer)"],
    [12, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Spaniels (English Springer)"],
    [13, 2, 2, 3, 6, 6, 9, 7,11,10,14, "Spaniels (English Springer)"],
    [14, 2, 2, 4, 3, 5, 6, 6, 7, 7, 9, "Spaniels (English Springer)"],
    [15, 2, 2, 3, 4, 5, 5, 7, 9,11,18, "Spaniels (English Springer)"],
    [ 1, 2, 2, 5, 5, 8, 7, 9, 9,12,12, "Brittany"],
    [ 2, 2, 2, 4, 4, 5, 5, 7, 7,11,10, "Brittany"],
    [ 3, 2, 2, 4, 4, 5, 5, 6, 7,10,11, "Brittany"],
    [ 4, 2, 2, 4, 4, 6, 7, 7, 8,10,10, "Brittany"],
    [ 5, 2, 2, 3, 4, 4, 5, 6, 7,10,11, "Brittany"],
    [ 6, 2, 2, 3, 4, 4, 5, 7, 6,11,11, "Brittany"],
    [ 7, 2, 2, 5, 5, 6, 8, 8,10,10,14, "Brittany"],
    [ 8, 2, 2, 4, 5, 6, 8, 8,13,11,16, "Brittany"],
    [ 9, 2, 2, 4, 5, 6, 7, 7, 9,10,15, "Brittany"],
    [10, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Brittany"],
    [11, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Brittany"],
    [12, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, "Brittany"],
    [13, 2, 2, 3, 5, 4, 6, 6, 8, 7,11, "Brittany"],
    [14, 2, 2, 4, 3, 5, 4, 6, 6, 8, 7, "Brittany"],
    [15, 2, 2, 5, 5, 7, 7, 8, 9,12,16, "Brittany"]
]
David Webb
  • 139
  • 2
  • 14

3 Answers3

1

The Swift compiler is unable to deduce the type of the akcTable variable, which is perhaps a bug in the compiler. Anyway, you need to make it explicit. This works in a playground:

var akcTable: [[AnyObject]] = [
    [ 1, 2, 2, 4, 6, 6,10,16,18,28,35, "Spaniels (English Springer)"],
    ... etc

but it doesn't work in the command-line Swift REPL (the error is “type of expression is ambiguous without more context”). This works in the REPL and in a playground:

var akcTable: [[Any]] = [
    [ 1, 2, 2, 4, 6, 6,10,16,18,28,35, "Spaniels (English Springer)"],
    ... etc
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

You could load it from JSON. Use NSJSONSerialization.

do
{
  let object:NSArray? = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
  //user
} catch let caught as NSError {
  //log
} 
Mitchell Currie
  • 2,769
  • 3
  • 20
  • 26
0

While both answers are true, you should really be making model objects for this data. Its going to save you a lot of time and headaches in the long run. Something like:

class Dog {
    var name: String?
    var breed: Int?
    ....
}

Then you can initialize all of your Dog instances and then put those into an array such that let akcTable: [Dog] = ...

Then every variable will be named and it'll be a lot easier to work with moving forward (i.e. you want have to remember a bunch of random indices when working with your data.

Peter Foti
  • 5,526
  • 6
  • 34
  • 47