Define vs Enum
#define
might be easier to type because you don't need =
or need to worry about the end ,
between each element. But you have an additional #define
that is less than DRY. I use enumerations, but in any case this is normal.
typedef enum { SongNameLabelTag = 1, PlayButtonTag = 2 } MyViewControllerTags;
vs.
#define SongNameLabelTag 1 #define PlayButtonTag 2
Naming convention
I name tags in the format: <name><short type description>Tag
eg. SongNameLabelTag
, PlayButtonTag
Tag Values ββin IB
The goal is to not give the element the same tag.
Itβs unpleasant for me to recall the last tag that I used when working in IB.
Keeping your data up to date seems like a solution, but it is annoying, and there are several times when it will not work.
eg. Moving an item to another controller. (I usually extract element groups to separate view controllers. This will cause your numbering to start with strange numbers or collide with existing elements.)
When prototyping and working quickly slow me down, I need to add each element tag as #define
. I like to work as fast as possible :)
My solution is to use random numbers . The maximum value you can use is NSIntegerMax (32-bit)
, which is 2147483647.
Most importantly, they must be quickly available!
Just tag this link every time you need some random tags:
http://www.random.org/integers/?num=100&min=1&max=999999999&col=1&base=10&format=html&rnd=new