在类Initializer中分配成员时,在Xcode中为自己分配一个propterty警告

max*_*max 0 xcode ios swift

我正在学习Swift以及Bloc.io Swiftris教程.

我为游戏板创建了一个Array2D类

// Generic arrays in Swift are actually of type struct, not class but we need a class in this case since class objects are 
// passed by reference whereas structures are passed by value (copied).
// Our game logic will require a single copy of this data structure to persist across the entire game.
// Notice that in the class' declaration we provide a typed parameter: <T>. 
// This allows our array to store any type of data and therefore remain a general-purpose tool.
class Array2D<T> {
    let columns : Int
    let rows : Int

    //  an actual Swift array; it will be the underlying data structure which maintains references to our objects.
    // ? in Swift symbolizes an optional value. An optional value is just that, optional.
    // nil locations found on our game board will represent empty spots where no block is present.
    var array: Array<T?>

    init(colums: Int, rows: Int) {
        self.columns = columns // !! Assigning a property to itself. 
        self.rows = rows
        // we instantiate our internal array structure with a size of rows * columns. 
        // This guarantees that Array2D can store as many objects as our game board requires, 200 in our case.
        array = Array<T?>(count:rows * columns, repeatedValue: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,Xcode Assigning a property to itself.通过以下行显示警告:

self.columns = columns
Run Code Online (Sandbox Code Playgroud)

我对警告感到有点困惑,这不就是我打算做的吗?警告意味着什么?

Raj*_*tia 7

你在构造函数定义中输入了一个拼写错误.

构造函数中的参数名称是colums.

将其更改为列或将违规行更改为

self.columns = colums
Run Code Online (Sandbox Code Playgroud)

它应该工作