CoreData: Edit Data

In an alert view:

 let action = UIAlertAction(title: "Update", style: .default) { (_) in

        let name = alert.textFields!.first!.text!
        let age = alert.textFields!.last!.text!


        selectedItem.setValue(name, forKey: "name")
        selectedItem.setValue(Int16(age), forKey: "age")

        do{
            try persistenceService.context.save()
        } catch {
            print("Error saving")
        }

        self.tableView.reloadData()
    }