我是精灵套件的新手。我将值放在矩阵的特定位置,但是当我打印该值时,我确实遇到了问题。模拟器打印:可选(零值),而不是仅打印值。
那么,我怎样才能将reValue放在矩阵的特定位置?
代码:
NumColumns = 4
NumRows = 4
func matrix() {
var valor = "0"
var principal = "0"
for var column = 0; column < NumColumns; column++ {
for var j = 0; j < NumRows; j++ {
valor = "\(numbers[column, j])"
cont++
principal = "\(cont)"
if valor != "0" {
numbers[column, j] = valor + principal
println("\(numbers[column, j])") //This print show: optional(nil >value)
}
else {
numbers[column, j] = principal
}
}
}
}
答案 0 :(得分:2)
您可以使用以下内容创建字符串的二维矩阵:
var numColumns = 4
var numRows = 4
// Create a 4x4 matrix of Strings
var array = [[String]](count: numColumns, repeatedValue:[String](count: numRows, repeatedValue:String()))
// Assign a string to a matrix element
array[1][2] = "element at (1,2)"
println (array[1][2])