Q:

How to change value of dictionary in View Controller from UiTableViewCell

So I have TableViewCell's that are being populated from 2 Dicitionaries in my view controller.
var categories : [Int : [String : Any]]!
var assignments : [Int: [String : Any]]!

I have a UiTextField in my cell that the user is supposed to be able to edit. I then want to be able to change the values of certain keys in that dictionary-based off what the user changes and re-display the table with those changes. My main problem is that I don't know how I will be able to access theese variables from within my cell. I have a method in my view controller that takes the row that the text field is in, along with the value of the textField, and updates the dictionaries. What I need is to be able to instantiate the view controller that the cell is in but I need the original instance that already has values loaded into the categories and assignments Dictionaries. If you have any other ideas on how I could accomplish this please post. 

A:

You can use delegate for sharing cell-data to your VC:
protocol YourCellDelegate() {
    func pickedString(str: String)
}

class YourCell: UITableViewCell {
    var delegate: YourCellDelegate! = nil
    @IBOutlet weak var textField: UITextField!
    .....//some set-method, where you can handle a text
    func textHandle() {
        guard let del = delegate else { return }
        del.pickedString(textField.text)
    }

    .....
}

And usage in your VC: When you create cell, set its delegate self:
...
cell.delegate = self
...

and sure you VC supported your Delegate Protocol:
class YourVC: UIViewController, YourCellDelegate {
}

And now, you MUST implement protocol method: 
class YourVC: UIViewController, YourCellDelegate {
....
    func pickedString(str: String) {

    }
....
}

All times, when you use textHandle() in your cell, pickedString(str: String) activates in yourVC with string from textField.
Enjoy!

