0

I want to set the text of a label in a prototype cell at a string that is stored in an array.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "unitOptionCell", for: indexPath)

    cell.textLabel?.text = currentConvertion.availableUnits(indexPath)

    return cell
}

The array is the follow:

var availableUnits: [String] {
    switch category {
    case .firstCategory:
        return ["test 1", "test 2", "test 3"]
    case .secondCategory:
        return ["test 4", "test 5", "test 6"]
    case .thirdCategory:
        return ["test 7", "test 8", "test 9"]
    }
}

where is the error?

1 Answer 1

1

If you use parenthesis, the compiler interprets that you're trying to make a call to a function. You should use brackets access the elements of your array, something like:

cell.textLabel?.text = currentConvertion.availableUnits[indexPath.row]
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.