Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

V-Appel

macrumors newbie
Original poster
Oct 1, 2013
5
0
Hi! I´m getting into objective c programing and I have stumbled across an error I can´t fix..

If I take away the last ";" in the line

Code:
 completion:^(BOOL finished) {[dmgLabel removeFromSuperview];}];

The errors goes away and a new one appears in the "if" part

Code:
-(void) damageCreep
{
    _targetCreep.health -= damage;
    
    UILabel *dmgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 50)];
    [dmgLabel setText:[NSString stringWithFormat:@"-%i", damage]];
    [dmgLabel setTextColor:[UIColor blackColor]];
    [dmgLabel setBackgroundColor:[UIColor clearColor]];
    
    [dmgLabel setCenter:_targetCreep.creepImgView.center];
    
    [_targetCreep.creepImgView.superview addSubview:dmgLabel];
    
    [[UIView animateWithDuration:1.0
                      animations:^{[dmgLabel setAlpha:0.0];}
                      completion:^(BOOL finished) {[dmgLabel removeFromSuperview];}];
         
if (_targetCreep.health <= 0)
     {
        
         //remove from store
         [_targetCreep.creepImgView removeFromSuperview];
         [[[CreepStore theCreepSore] activeCreeps] removeObject:_targetCreep];
         
         //Stop firing
         [self stopFiring];
     }
     if (CGRectIntersectsRect(_targetCreep.creepImgView.frame, _rangeView.frame) == NO)      
     {
         [self stopFiring];
     }
    
}

http://gyazo.com/4e23169996ac5ff6fcf9a2ca50a55678

then
http://gyazo.com/4de3a7cb8d56727084f57f085658e426

any idées?

Thanks!
 
Look carefully at the start of the statement:
Code:
      [[UIView animateWithDuration:1.0
                      animations:^{[dmgLabel setAlpha:0.0];}
                      completion:^(BOOL finished) {[dmgLabel removeFromSuperview];}];
Then go and match up your ]'s and {}'s. Notice anything?

Personally, this is one reason I use spaces between {} and []. Because mashingeverythingtogethermakeserrorshardertosee.
 
If you double click on a brace or bracket the Xcode editor will select all the text to the matching brace or bracket.
 
Look carefully at the start of the statement:
Code:
      [[UIView animateWithDuration:1.0
                      animations:^{[dmgLabel setAlpha:0.0];}
                      completion:^(BOOL finished) {[dmgLabel removeFromSuperview];}];
Then go and match up your ]'s and {}'s. Notice anything?

Personally, this is one reason I use spaces between {} and []. Because mashingeverythingtogethermakeserrorshardertosee.

You're not going to cut the newbie a break and tell him what's wrong with that line? Seems cruel.

:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.