tag:crieit.net,2005:https://crieit.net/tags/UIKit/feed 「UIKit」の記事 - Crieit Crieitでタグ「UIKit」に投稿された最近の記事 2018-11-02T15:43:53+09:00 https://crieit.net/tags/UIKit/feed tag:crieit.net,2005:PublicArticle/14591 2018-11-02T15:43:53+09:00 2018-11-02T15:43:53+09:00 https://crieit.net/posts/window-is-not-equal-to 「window is not equal to」というログメッセージ <p>ログに"window is not equal to"というメッセージが出力された。windowとあるので、Storyboardに問題があるのかと思ったが違った。また、メッセージの中にあるViewControllerが原因でもなかった。遷移元のViewControllerでperformSegue(withIdentifier:sender:)を2回呼んでいたことが原因だった。</p> <blockquote> <p>'s window is not equal to 's view's window!</p> </blockquote> <h3 id="ヒントになった"><a href="#%E3%83%92%E3%83%B3%E3%83%88%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%9F">ヒントになった</a></h3> <p><a target="_blank" rel="nofollow noopener" href="https://teratail.com/questions/12348">teratail「window is not equal to」というログメッセージ</a></p> <h3 id="問題のコード"><a href="#%E5%95%8F%E9%A1%8C%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89">問題のコード</a></h3> <pre><code class="swift">if user == nil { self.performSegue(withIdentifier: "segueA", sender: nil) return // このreturnを忘れた } self.performSegue(withIdentifier: "segueB", sender: nil) // 終了 </code></pre> <p>今回のケースでは、userがnilでないときに追加して他のことをするならguard文で書くのが妥当。上記のコードでは、遷移先の選択のみなので、guard文ではなくif else で並列に書くと意図が明確になると思う。</p> あぜち(おばあちゃん)