vendredi 6 mars 2015

multidimensional arrays in swift inside a ViewController

I am relatively new to Swift and I guess the problem is more of a general problem regarding initialization.


I need to create a multidimensional array where I can access all values which are mostly strings in a UIViewController instance. See the following example with placeholders as Strings (which are supposed to be real words, but I tried to keep it simple until it works):



let firstArray = ["1","2","3"]
let secondArray = ["4","5","6"]
let thirdArray = [firstArray,secondArray]
let fourthArray = ["1","2","3"]
let fifthArray = ["4","5","6"]
let sixthArray = [fourthArray, fifthArray]
let seventhArray = [thirdArray, sixthArray]


in a Playground this runs fine and is accessible as i want it. But inside my ViewController instance the compiler returns the following error(s):



'myViewController.Type' does not have a member named firstArray


and the same for every time I try to place an array inside an array. Inside my .swift file it looks like this:



import UIKit

class tricktionaryViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let firstArray = ["1","2","3"]
let secondArray = ["4","5","6"]
let thirdArray = [firstArray,secondArray]
let fourthArray = ["1","2","3"]
let fifthArray = ["4","5","6"]
let sixthArray = [fourthArray, fifthArray]
let seventhArray = [thirdArray, sixthArray]
let textCellIdentifier = "TextCell"

//.... some functions following

}


I actually tried to create classes for the first level of arrays, but still the same problem. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire