0

I changed my core data model by adding an attribute to an entity. I've done a lightweight migration, but when I run the app I get a nil for some for the added attribute and thus a crash. I simply want to check for a nil and exclude the attribute if it is nil so as to avoid the crash. I've tried to do this with an if statement, but I get the error in the title. How can I get around this?

if comments == nil {
        cell.textLabel!.text! = "\(totalWorkTimeInHours) hours"
        cell.detailTextLabel!.text! = "Date: \(dateString)"

    } else {

        cell.textLabel!.text! = "\(totalWorkTimeInHours) hours"
        cell.detailTextLabel!.text! = "Date: \(dateString)\nComments: \(comments)"

    }

"Comments" is a string from Core Data. I know the error has something to do with the fact that I can't compare a string with nil, but I'm not sure how else to do it.

Thanks for the help!

Leighton
  • 6,559
  • 7
  • 21
  • 28

1 Answers1

2
var comments: String? = nil
if let comments = comments {
    println(comments)
} else {
    println("empty")
}    
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571