Quantcast
Channel: How do I safeguard that addChild(x) isn't added twice? - Stack Overflow
Browsing index pages (3 articles)
↧

How do I safeguard that addChild(x) isn't added twice?

I keep running into a problem where addChild(myLabel) is triggered twice, resulting in a crash. Is there a way to safeguard that addChild(myLabel) isn't triggered if it has already added the label? I...

View Article


Answer by Cerlin for How do I safeguard that addChild(x) isn't added twice?

How about keeping track of that in a boolean, like var isChildAdded = false if !isChildAdded { addChild(myLabel) isChildAdded = true }

View Article


Answer by Narek Tserunyan for How do I safeguard that addChild(x) isn't added...

If you mean usage of this function addChild(_ childController: UIViewController) then I would suggest to check by if !controller.children.contains(controller1) { // your actions } Otherwise if it is...

View Article
Browsing index pages (3 articles)


Latest Images