保存 NSDate 的核心数据保存错误(NSValidationErrorKey,Cocoa 错误 1570) [英] Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) saving NSDate
问题描述
我在 Xcode 中保存到 Core 数据对象时出错.
I'm getting an error with saving to a Core data object in Xcode.
Xcode 说错误出在 NSDate 变量 'datum' 中,但我几乎尝试了所有方法.错误是:
Xcode says that the error is in the NSDate variable 'datum' but I have tried almost everything. Error is:
2011-07-12 18:01:29.068 WeekLijstje[3205:207] Core Data Save Error
NSValidationErrorKey datum
NSValidationErrorPredicate (null)
NSValidationErrorObject
<DagLijst: 0x6e2fcd0> (entity: DagLijst; id: 0x6e2fd30 <x-coredata:///DagLijst/t99F423FC-AAE9-4692-9264-EF0FF7A020572> ; data: {
Voedsel = nil;
datum = nil;
hoeveelheid = 0;
punten = 0;
})
NSLocalizedDescription:The operation couldn’t be completed. (Cocoa error 1570.)
一小段代码:
DagLijst *newDaglijst = [NSEntityDescription insertNewObjectForEntityForName:@"DagLijst" inManagedObjectContext:self.managedObjectContext];
NSDate *selDatum = [NSDate date];
newDaglijst.punten = [NSNumber numberWithInteger:10];
newDaglijst.hoeveelheid = [NSNumber numberWithInt:100];
newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;
NSError *error = nil;
if (![newDaglijst.managedObjectContext save:&error]) {
...
也是 DagLijst 对象的类:
Also the class of the DagLijst object:
@interface DagLijst : NSManagedObject {
@private
}
@property (nonatomic, retain) NSDate * datum;
@property (nonatomic, retain) NSNumber * punten;
@property (nonatomic, retain) NSNumber * hoeveelheid;
@property (nonatomic, retain) Voedsel *Voedsel;
@end
所以你可以看到我将一个 NSDate 放入 'datum' 变量中.但在执行时我仍然收到错误.
So you can see that I put an NSDate into the 'datum' variable. But on execution I still get an error.
推荐答案
cocoa 错误 1570
表示未填写必填字段.在这种情况下,您有两个 nil
属性:Voedsel
和 datum
.
The cocoa error 1570
means that mandatory fields are not filled in.
In this case, your have two attribues that are nil
: Voedsel
and datum
.
我在你的代码中看到:
newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;
检查geselecteerdVoedsel
和selDatum
是否为nil 或它们是否被过度发布并最终为nil.如果它们是可选数据(但我不这么认为),请在 coredata 中将它们定义为可选数据.
Check that geselecteerdVoedsel
and selDatum
are not nil or that they are overreleased and finish to be nil.
If they are optional data (but I don't think so), define them as optional in coredata.
希望对您有所帮助
这篇关于保存 NSDate 的核心数据保存错误(NSValidationErrorKey,Cocoa 错误 1570)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!