2

I've seen the tag property in all UI frameworks I worked with: UIKit, Forms, OpenStep, even Delphi 6. Was it in the original Macintosh Toolbox or Xerox's framework? WhAt was the original idea behind it?

0

2 Answers 2

1

Before data binding was a popular method in UI libraries, the Tag property allowed you to place an Identifier that might be associated with a backend object (in Windows Forms the Tag property was an object, so you could place the entire object into the Tag).

1

Quoting from the docs for UIView...

tag Property
An integer that you can use to identify view objects in your application.

Assuming you've seen the docs for such attributes, you're probably really asking why people still use them today. They are there as a convenience to developers to use however they want. In an object graph containing multiple objects of the same class (buttons, menu items, etc.), different tag values can be assigned to help identify one button over another. Or they can be used to hold a pointer to some more data (not necessarily a recommended approach), or bit field, or whatever.

Nowadays, memory and CPU resources are such that we can throw in other stuff to help identify things at runtime. The integer tag attribute was used in "the good old days" when memory and CPU resources were more scarce. It doesn't hurt anything to leave the tag attribute in there, and many developers still use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.