I want to test if an NSNumber attribute of a NSManageObject Subclass has been set or not. Note, that the attribute is of NSNumber / Integer16 I have tried several approaches but none worked (these below always evaluate to false):
// Note: patient.zyklus_laenge is of NSNumber (Integer16)
// does not work
id value = patient.zyklus_laenge;
if (value == [NSNull null]) {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%d", 28];
} else {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%@", patient.zyklus_laenge];
}
// does not work
if (!patient.zyklus_laenge) {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%d", 28];
} else {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%@", patient.zyklus_laenge];
}
// does not work
if ([patient.zyklus_laenge isEqual:nil]) {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%d", 28];
} else {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%@", patient.zyklus_laenge];
}
// does not work
if (patient.zyklus_laenge == nil) {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%d", 28];
} else {
self.zyklusLaengeTextField.text = [NSString stringWithFormat:@"%@", patient.zyklus_laenge];
}
Can anyone enlighten me and explain me why these are not working?