Thanks. Here is what I am working with: Below is my Controller1 with the function updateData which I want to use in other controllers. The yellow highlighted part was added from your example but I am not sure this is correct as I want to call this function inline (not on a button click). What oud my controller that makes the call look like?
I really do appreciate the help - I am learning!
import UIKit
import CoreData
class Controller1: UIViewController {
**@IBOutlet** **weak** **var**
newMaxLiftText: UITextField!
**@IBOutlet** **weak** **var**
newMaxLiftLabel: UILabel!
**@IBOutlet** **weak** **var**
maxWeightLiftedLabel: UILabel!
**@IBAction** **func**
newWeightButon(_ sender: UIButton) {
maxWeightLiftedLabel.text = newMaxLiftText.text
updateData()
}
**@IBAction** **func**
delerteDataBtton(_ sender: UIButton) {
deleteData()
}
**@IBAction** **func**
loadDataButton(_ sender: UIButton) {
createData()
}
override func
viewDidLoad() {
**super**.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(updateData(noti:)), name:Notification.Name.Action.CallVC1Method, object: nil)
}
////////////// Update Function ////////////////
**func** updateData(){
**guard** **let** appDelegate = UIApplication.shared.delegate **as**? AppDelegate **else** { **return** }
**let** managedContext = appDelegate.persistentContainer.viewContext
**let** fetchRequest:NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "Chest")
fetchRequest.predicate = NSPredicate(format: "name = %@", "Dumbell Chest Press")
**do**
{
**let** test = **try**
managedContext.fetch(fetchRequest)
**let** objectUpdate = test[0] **as**! NSManagedObject
objectUpdate.setValue(maxWeightLiftedLabel.text!, forKey: "weight")
**do**{
**try** managedContext.save()
}
**catch**
{
print("Error: ",error)
}
}
**catch**
{
print(error)
}
}