1

So I have a code which looks working fine except I see an error :

App[0000:000000] Warning: Attempt to present <_App.nextView: 0x000000000> on <_App.PreviousView: 0x000000000> whose view is not in the window hierarchy!

So I searched and I think my situation is like this answer.

Except, I need multiple segues as far as I know. So I don't know how to handle, my code is similar like this :

if stateNumber == 3 && !isCondition01True {
        performSegue(withIdentifier: "nextView", sender: Any?.self)
    }
if stateNumber == 3 && !isCondition02True {
        performSegue(withIdentifier: "nextView", sender: Any?.self)
// and like +30 more statements like this

Is there a workaround for like these situations? Like a code to trigger a segue once? I tried to group this statements before but I failed (I'm still learning swift, so I may have missed something).

vadian
  • 274,689
  • 30
  • 353
  • 361
Aliriza
  • 11
  • 3
  • Use `else if`, not only `if`. And I guess that it's in a preference order. – Larme Oct 15 '18 at 10:50
  • where you put this code – Shehata Gamal Oct 15 '18 at 10:51
  • Unrelated but what is `Any?.self` supposed to be? And please post more meaningful code. Your example will perform the same segue which can be checked with **one** if statement. – vadian Oct 15 '18 at 10:52
  • guys. he just calling same segue many times. more than one if clause succeeds. – hasan Oct 15 '18 at 10:53
  • PS: The error/warning is not related to the question about multiple if statements – vadian Oct 15 '18 at 11:00
  • @vadian , I'm using `Any?.self` for a while, otherwise my segues won't work. If I'm not mistaken, adding `.self` was Xcode's own suggestion. (I create those segues between storyboard's viewcontrollers). And I'm using multiple if's because this is a game, there are multiple situations (which are not connected each other) which led to "game lost" screen. – Aliriza Oct 15 '18 at 11:27
  • @hasan , exactly – Aliriza Oct 15 '18 at 11:28
  • 1
    The `sender` parameter is supposed to be an **instance** (not a type) like `self` or `stateNumber` or ***no sender*** is `nil`. Nothing else. `Any?.self` is hilarious but pointless. – vadian Oct 15 '18 at 11:30

1 Answers1

0

You could try else or you can try to combine them as following:

if stateNumber == 3 {
    if !isCondition01True || !isCondition02True {
        performSegue(withIdentifier: "nextView", sender: Any?.self)
    }
}

etc ...

hasan
  • 23,815
  • 10
  • 63
  • 101