0

I have the exact same problem as a earlier question xcode swift indexing forever i have spotted my problem. This array:

var VragenInformatie = [[["Spelletjeskamer",""],["Keuken",""],["Garage",""],["Binnenplaats",""],["Zitkamer",""],["Slaapkamer",""],["Studeerkamer",""],["Eetkamer",""],["Badkamer",""]], [["De Wit",""],["Pimpel",""],["Blaauw van Draet",""],["Roodhart",""],["Groenewoud",""],["Van Geelen",""]], [["Loden pijp",""],["Pistool",""],["Engelse sleutel",""],["Dolk",""],["Touw",""],["Kandelaar",""]]]

I have tried: clean, deleted derived data, and even delete workspace thingy but nothing worked. But I still need this array does anybody have an idea or suggestion how to get a work around?

UPDATE:
I gone use this array for a tableview so is there maybe an other way for tableview data source?

Thanks in regards!

Community
  • 1
  • 1
Cing
  • 806
  • 1
  • 11
  • 29

1 Answers1

2

I think, the problem is the type inference, which is quite hard for your 3D array. You should give more structure to this, e.g. via tuples

let VragenInformatie: [[(String, String)]] = [
    [("Spelletjeskamer",""), ("Keuken",""), ("Garage",""), ("Binnenplaats",""), ("Zitkamer",""), ("Slaapkamer",""), ("Studeerkamer",""),("Eetkamer",""), ("Badkamer","")],
    [("De Wit",""), ("Pimpel",""), ("Blaauw van Draet",""), ("Roodhart",""), ("Groenewoud",""), ("Van Geelen","")],
    [("Loden pijp",""), ("Pistool",""), ("Engelse sleutel",""), ("Dolk",""), ("Touw",""), ("Kandelaar","")]
]

Anyway, not a neat, clean design. Think about creating a structure or class which encapsulate your data (sorry, my Dutch is not sufficient to understand what you try to provide to a table view).

Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
  • i really think it was indexing for ever because it wasn't making any progress – Cing Jan 27 '16 at 17:47
  • Thanks man it really worked!! i didn't you also could use () for array's – Cing Jan 27 '16 at 17:56
  • This is called a [tuple](http://www.raywenderlich.com/115300/swift-2-tutorial-part-3-tuples-protocols-delegates-and-table-views), a new data type which came with Swift. But this is not the solution. The solution was that I relinquished type inference by declaring the type via `: [[(String, String)]]`. – Michael Dorner Jan 27 '16 at 17:59
  • but how would i acces the strings this doesn't work Vrageninformation[0][2][0] – Cing Jan 27 '16 at 20:23
  • btw you can at least tell that it is dutch – Cing Jan 27 '16 at 20:24
  • Read e.g. [this introduction](http://www.raywenderlich.com/115300/swift-2-tutorial-part-3-tuples-protocols-delegates-and-table-views). You can access tuples, e.g. by `Vrageninformation[0][2].0` or `Vrageninformation[0][2].1`. – Michael Dorner Jan 27 '16 at 20:45
  • i get this error Cannot subscript a value of type 'inout [[(String, String)]]' (aka 'inout Array>') – Cing Jan 27 '16 at 20:49