Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting shadowColor with property syntax gives compiler error: Expected identifier before '[' token
    primarykey
    data
    text
    <p>I have an iPad app in which I'm setting the shadow color of a UILabel in a UIView's initWithFrame: method. When I use the following syntax:</p> <pre><code>m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5]; </code></pre> <p>I get this compiler error:</p> <p><strong>Expected identifier before '[' token</strong></p> <p>However, when I use the following syntax:</p> <pre><code>[m_label setShadowColor:[UIColor colorWithWhite:1.0 alpha:0.5]]; </code></pre> <p>It compiles without complaint.</p> <p>Using property syntax for other properties of the UILabel is working fine (shadowOffset, autoresizingMask, backgroundColor, font, textColor, etc.).</p> <p>Incidentally, I get the same error message when the statement is simply this:</p> <pre><code>m_label.shadowColor; </code></pre> <p>Whereas this, for example, gives no error:</p> <pre><code>m_label.shadowOffset; </code></pre> <p>FWIW, the entire method looks like this:</p> <pre><code>#define shadowColor [UIColor colorWithWhite:1.00 alpha:0.5] #define selectedColor [UIColor colorWithWhite:0.25 alpha:1.0] #define unselectedColor [UIColor colorWithWhite:0.45 alpha:1.0] #define CLOSEBUTTON_WIDTH 26.0 #define CLOSEBUTTON_HEIGHT 26.0 - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { m_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height)]; m_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; m_imageView.backgroundColor = [UIColor clearColor]; m_imageView.image = [[UIImage imageNamed:@"tab.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0]; m_imageView.highlightedImage = [[UIImage imageNamed:@"tabSelected.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0]; m_label = [[UILabel alloc] initWithFrame:CGRectZero]; m_label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; m_label.backgroundColor = [UIColor clearColor]; m_label.font = [UIFont boldSystemFontOfSize:12.0]; m_label.textColor = unselectedColor; m_label.shadowOffset = CGSizeMake(0.0, 1.0); m_label.shadowColor = shadowColor; // Expected identifier before '[' token [m_label setShadowColor:shadowColor]; m_closeButton = [[UIButton alloc] initWithFrame:CGRectMake(9.0, 1.0, CLOSEBUTTON_WIDTH, CLOSEBUTTON_HEIGHT)]; [m_closeButton setBackgroundImage:[UIImage imageNamed:@"tabClose.png"] forState:UIControlStateNormal]; [m_closeButton addTarget:self action:@selector(closeTab) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:m_imageView]; [self addSubview:m_label]; [self addSubview:m_closeButton]; self.backgroundColor = [UIColor clearColor]; } return self; } </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload