Help with equals code

Discussion in 'iOS Programming' started by PewPew, Oct 29, 2010.

  1. PewPew macrumors newbie

    Joined:
    Oct 28, 2010
    #1
    Hi,
    I'm making an alarm-app and I came across a problem;
    My equals code:
    Code:
    	if(afLabel.text == afLabel2.text)
    	{
    		afLabel.text = @"!!!!!";
    	}
    	else{
    		afLabel.text = clockLabel.text;
    		afLabel2.text = testAlarm2.text;
    }
    Whats in clockLabel:
    Code:
    [formatter setDateFormat:@"hh:mm a"];
    [clockLabel setText:[formatter stringFromDate:date]];
    testAlarm2:
    Code:
    [testAlarm setText:[pickAlarm.date descriptionWithCalendarFormat:@"%I:%M %p" timeZone:nil locale:nil]];
    I did that so that the time both will be displayed as ex. 08:15 AM, but it just doesn't seem to work even though they have the exact same text in them:
    (The upper one is afLabel and the lower one is afLabel2)
    [​IMG]

    I know this way probably isn't a good way, but I'm new so, yeah.. :rolleyes:
    Thanks in advance!:D
     
  2. bindle macrumors regular

    Joined:
    Aug 29, 2008
    #2
    Code:
    if(afLabel.text == afLabel2.text)
    
    ^^This isn't the correct way to compare the string values. You're comparing pointers.

    The correct way is using NSString's isEqualToString: method:
    Code:
    if ([afLabel.text isEqualToString: afLabel2.text])
    
     
  3. PewPew thread starter macrumors newbie

    Joined:
    Oct 28, 2010
    #3
    Yes! Thank you very much, that fixed the problem!:D
     

Share This Page