0

I am trying to store an int value inside a tuple array. The array has this format:

var array: [(object1:Object1,object2:Object2,number:Int)]

I have a tableview, with buttons and textfields inside it's cells. In a button, with an action sheet string picker i give values to the textFields.

 func buttonPressed(){
let cell = button.superview?.superview? as? CustomCellClass

//i use a string picker to fill the JVFLoatLabeledTextField
// then i acces link the arrays, index to the current cell


let currentIndex = tableView.indexPath(for: cell)

 array[currentIndex.row].number = Int(cell.textfield.text!)!

 //i also insert the objects in the array, but they work fine

}

but when i try to acces all the stored data from different cells like this:

    for tuple in array {

print(tuple.object1.name)
print(tuple.object2.name)
print(tuple.number)

}

the output will be: object1.name, object2.name, 0 .... every tuple.number has the value 0.

If anyone gives any suggestion I'd appreciated it...

1 Answer 1

1

To narrow down the problem I would try:

array[currentIndex.row].number = currentIndex.row

If you get the expected result when you iterate through the array that will demonstrate that the issue is not with the tuple array. Check value returned from the expression

Int(cell.textfield.text!)!

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.