Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    This should be the selected answer! Also, it's funny so it's got that going for it. Commented Feb 8, 2022 at 1:20
  • This doesn't work when an app has multiple active scenes. Let's say there is scene A, B, and C. Let's say scene A is the last one that was connected so currentScene is set to scene A. Now let's say a view controller in scene C wants to get its delegate. This code will return the delegate for scene A, not scene C.
    – HangarRash
    Commented Mar 6, 2023 at 6:30
  • @HangarRash, that's right but this answer is made for single scene apps ;) Commented Jun 8, 2023 at 16:30
  • @SerjRubens Where does the answer claim that it is only for single scene apps? As written, the answer clearly assumes multiple scenes. And that's the problem because it doesn't handle them correctly. BTW - a view controller has easy access to its scene. None of this code is needed.
    – HangarRash
    Commented Jun 8, 2023 at 16:56
  • first(where:) should be used instead of for cycle here Commented May 12 at 17:28