Unusual Error?

Discussion in 'iOS Programming' started by V-Appel, Oct 1, 2013.

  1. V-Appel macrumors newbie

    Joined:
    Oct 1, 2013
    #1
    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!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    What's the specific error if you leave the ';' in?
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    If you double click on a brace or bracket the Xcode editor will select all the text to the matching brace or bracket.
     
  5. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #5
    You're not going to cut the newbie a break and tell him what's wrong with that line? Seems cruel.

    :)
     

Share This Page