Quantcast
Channel: How do I safeguard that addChild(x) isn't added twice? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

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

$
0
0

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 was looking for a bool, something like myLabel.isAddedToView but don't think there is one. I also tried

guard let test = addChild(myLabel) else {print("error") return}

But this gives me the error

Initializer for conditional binding must have Optional type, not Void'


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images