-4

So I am making an interactive story programmatically and I want a way to restart the game. (i.e clear everything) the only thing that I have found is

func refreshView() ->() {

    // Calling the viewDidLoad and viewWillAppear methods to "refresh" the VC and run through the code within the methods themselves
    self.viewDidLoad
    self.viewWillAppear

}

func refreshVC(sender: AnyObject) {
    self.refreshView()
}

except it is saying "expression resolves to an unused function" Anyone know a way to solve this?

Sam
  • 1
  • 1
  • 1
  • 1
    The immediate problems are that the `refreshView()` method does not need to return anything. So delete `-> ()`. Next, `viewDidLoad()` and `viewWillAppear()` need `()` on the end. You have a bigger problem though, I think. This probably isn't the best way to go about "resetting." You could try removing the current view controller and adding a new view controller of the same type. You could try removing the current window and adding a new window in your app delegate (essentially restarting the whole app). We can't know the best answer without knowing your app. – keithbhunter Aug 30 '17 at 19:19
  • Possible duplicate of [How to reset/restart viewcontroller in Swift?](https://stackoverflow.com/questions/30633566/how-to-reset-restart-viewcontroller-in-swift) – Ahmad F Aug 30 '17 at 19:22
  • 2
    FYI - never call `viewDidLoad` or `viewWillAppear` or any other view controller life cycle method yourself. – rmaddy Aug 30 '17 at 19:31

1 Answers1

1

You're missing the () after viewDidLoad and viewWillAppear.

EDIT: Okay, adding the parentheses will make your code compile. But after actually looking at it, it sounds like what you really want to do is to call setNeedsDisplay() on the view, which will cause the entire view to be re-displayed.

Charles Srstka
  • 16,665
  • 3
  • 34
  • 60