I need to fill a array with values which is in a class:
class a {
var selectedRows: [Int]?
init() {}
init(number: Int) {
selectedRows?.append(number)
}
}
How can I fill this array from another class?
I need to fill a array with values which is in a class:
class a {
var selectedRows: [Int]?
init() {}
init(number: Int) {
selectedRows?.append(number)
}
}
How can I fill this array from another class?
you should initialitze the array. The array is not set and therefore it will not add any number.
best practice in my opininion would be:
class a {
var selectedRows: [Int] = []
init() {}
init(number: Int) {
selectedRows.append(number)
}
}
you can also add an append function
append(number: Int) {
selectedRows.append(number)
}
or extend the array to add custom functionality as asked here: How can I extend typed Arrays in Swift?