I have a query on this. Please look at the sample code below:
UIButton *button;
button.tag = 1;
and
int but = (int)[(UIButton*)sender tag];
The first line I set tag number 1 to button variable, using the .tag method. And in the second line, I used (int)[(UIButton*)sender tag]; to extract and cast the sender into an integer value. My question would be, what is the difference between .tag and tag method?
There should be no difference. Before Objective C 2.0, the dot methods didn’t exist; these were added, but they function as shortcuts to the longer bracketed call.
In your particular code example, in the first code block,
buttondoesn’t hold a pointer to a button. You’d need to callthis would set the tag to 1. The second code block takes an existing button and extracts its tag to an
int, as you indicated. A better example of parallel methods would be:button.tag = 1;and[button setTag:1];, orint tag = button.tag;andint tag = [button tag];