Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2018 10:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
How to call a function of a vc inside another vc.
//Inside the main vc i put a function like this
//Function fetches data and calcs the total
func changeNavTitle() {
// It does some stuff and then updates navigation label (you can change this to another label)
titleNav.title = "\(sum)\(currencySymbol)"
fetchedResultsController.changedContent = false
//Inside the other vc I call the function like this:
//I have an IBAction that's calling the dismiss
//If your dismiss is handled otherwise and you can't put both in one function, you can still add the code in the
//completion of dismiss
//If you need help with the completion, watch this treehouse course:
@IBAction func save(_ sender: Any) {
//[...] does some stuff for CoreData
//Calls the function to update the total
//IMPORTANT: Change the "TableViewController" to the class name of your vc. Else it wont be able to access that function!!!
let presentedBy = presentingViewController as? TableViewController
dismiss(animated: true, completion: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment