I'm using CoreData in a Swift project.
I have a current user in my database, and I want to update his birthdate. By default, his birthdate is not register: in CoreData, "optional" is checked for this attribute.
I have some trouble to test if this birthdate value is nil or not. After retrieving the user, I tried to test this attribute.
I tried this following code
if user!.birthdate.isEqual(nil) {
println("Birthdate is nil")
}
and this one
if user!.birthdate == nil {
println("Birthdate is nil")
}
The first one is always wrong, and the second one cannot compile.
However, if I tried to print the description of the value just before, I've seen this in the log:
Printing description of $R0:
<nil>
But my variable view show me a different value:
So, I'm little bit lost between theses informations. Does anyone know how can I test an empty NSDate from CoreData in Swift?
Thanks,
Ben
EDIT
I've also tried this code from an other question
if let birthdate = user!.birthdate{
// my code here
} else {
println("Birthday nil")
}
It doesn't compile, because "Bound value in a conditional binding must be Optional type". My attribute is Optional for CoreData, but not in my NSManagedObject file generated.