DEV Community

Midhet Sulemani
Midhet Sulemani

Posted on

Tags in Swift UIViews

Is using tag in your UIView to store the state of the UIView a bad practice?

Top comments (6)

Collapse
 
ithinker profile image
Roman Temchenko

Yeah. Usually it is the last resort when it is very hard to manage view for whatever reason. As other answer suggests you may toggle some state variable on a view controller or the view itself if you can subclass it.

Collapse
 
midhetfatema94 profile image
Midhet Sulemani

Thanks for the opinions :)

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

Can you elaborate more on that? What exactly are you using tag for in your UIView?

Collapse
 
midhetfatema94 profile image
Midhet Sulemani

I have a customised video view and a fullscreen button in it. Both enter and exit fullscreen methods are linked to the outlet of the same fullscreen button. I toggle the tag of this button to 0 and 1 and according to its tag, I will decide whether to enter or exit the fullscreen. Is this an unreliable approach? If yes, then can you suggest a better one?

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

Why not a Bool var like isFullScreen in your view controller? Seems more clear to me, you toggle the variable and you know what you have to do

Thread Thread
 
midhetfatema94 profile image
Midhet Sulemani

Thanks for the opinions :)