Call function right after unwind - Swift 2

432 views Asked by At

I'm working on a game which has just 2 view controllers (view 1 & view 2).

View 1 is the actual game view where the user plays and view 2 is called with a PerformSegueWithIndentifier and is presented modally over current context when the user gets a high score.

On View 2 there are 2 options, one of which is called "Play Again".

I would like to know how I can dismiss the current view and call a function called playagain() on view 1 when they click on the 'Play Again" button.

This function basically resets the game so the user can play again.

Since the user has an option on View 2, to share a screenshot of their current score, calling playagain() and resetting the game prior to the segue is not an option.

It would be really helpful if someone could tell me how to do this on Xcode 7 beta and swift 2.

I should also point out that I'm really new to development, so if you could provider solution explanations that are beginner friendly that would be amazing.

1

There are 1 answers

0
Nilesh Patel On

Multiple ways are there to do this...

  1. You can use delegation pattern, Refer this link for detail explanation.
  2. You can use NSNotificationCenter for this, Refer this link for more info.