Your code both compiles and works perfectly:
var inactiveLocationArray = [String]()
var activeLocationArray = [String]()
let locationArrays: [[String]] = [inactiveLocationArray,activeLocationArray]
Perhaps it doesn't do what you expect or desire, but it does work. The result is an array of arrays, precisely as expected.
but it gives error: Value of type (NSObject) -> () -> Controller has no member activeLocationArray
That's because your code is in the wrong place. All executable code must be inside a function of some kind. Yours isn't. Example:
class Controller : NSObject {
func someMethod() {
var inactiveLocationArray = [String]()
var activeLocationArray = [String]()
let locationArrays: [[String]] = [inactiveLocationArray,activeLocationArray]
}
}
If you move the let locationArrays
line out of its containing method (here, someMethod
), sure, it won't compile. But that has nothing to do with arrays. It has to do with the fact that the line is executable code, and cannot live off in the ether.