1

I have a 2D array that worked in Beta 2. However, in Beta 3 I'm getting '@lvalue $T15 is not identical to T?' when setting via subscript.

class Array2D<T> {
let columns: Int
let rows: Int
let array: [T?] 

init(columns: Int, rows: Int) {
    self.columns = columns
    self.rows = rows
    array = [T?](count: rows*columns, repeatedValue: nil)
}

subscript(column: Int, row: Int) -> T? {
    get {
        return array[row*columns + column]
    }
    set {
        array[row*columns + column] = newValue  // Error here
    }
}}

Any thoughts on how to resolve this?

1 Answer 1

7

In Beta3 constant arrays are completely immutable while variable arrays are entirely mutable. Change let array: [T?] to var array: [T?] and your code should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.