0

i try to change the labelcolor, if the "date" in my detailTextLabel.text older then today..

        // Configure the cell...

    cell.textLabel?.textColor = UIColor.blueColor()
    cell.detailTextLabel?.textColor = UIColor.darkGrayColor()

    let item = frc.objectAtIndexPath(indexPath) as! Item
    cell.textLabel?.text = item.name! + "-" + item.etage! + "-" + item.raum!
    let note = item.date
    cell.detailTextLabel!.text = "\(note!)"

    if note == "01.04.2016 23:00" {
    cell.detailTextLabel?.textColor = UIColor.redColor()
    } else {

    }

    return cell
}

How can i do this? It works with a specific date but not with NSDate() or something like this. I go crazy!

big thx!

slevin
  • 11
  • 5
  • check this http://stackoverflow.com/questions/26807416/check-if-date-is-before-current-date-swift and make sure compare with same format – Bhavin Bhadani Apr 08 '16 at 08:01
  • apparently your Item.date is in String format so it's not possible to directly compare with an NSDate object. – Rukshan Apr 08 '16 at 08:36

1 Answers1

0

As pointed there you can make something like this:

...
let note = item.date
let now = NSDate()

if note.earlierDate(now).isEqualToDate(note)  {
    cell.detailTextLabel?.textColor = UIColor.redColor()
}
Community
  • 1
  • 1
giacavicchioli
  • 334
  • 2
  • 14