Combining UILabel declarations onto one line

Why Xcode doesn't allow this:

UILabel*redlabel,greenlable,bluelabel;

      

But I like it:

UILabel*redlabel;
UILabel*greenlabel;
UILabel*bluelabel;

      

You can do this with other classes, so why not UILabel? It gives an error: "The interface type could not be statically allocated."

+3


source to share


3 answers


It will work:



UILabel *redlabel, *greenlable, *bluelabel;

      

+4


source


By writing this:, UILabel *redlabel, greenlable, bluelabel;

you are simply declaring a pointer to UILabel

and two UILabel

s, not pointers.

This is equivalent to writing:

UILabel *redlabel;
UILabel greenlabel;
UILabel bluelabel;

      



Try this instead, you need all three to be pointers:

UILabel *redlabel, *greenlable, *bluelabel;

      

+7


source


The correct syntax is:

UILabel *redlabel,*greenlable,*bluelabel;

      

+1


source







All Articles