核心数据保存错误(NSValidationErrorKey,Cocoa错误1570)保存NSDate [英] 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.)
一个小代码snipet:
A small code snipet:
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.
我搜索并尝试了很多事情。
希望我有一个清楚的问题。
I have searched and tried many things. Hope i'm a bit clear about the problem. Please can someone help me (sorry for the bad English).
推荐答案
可可错误 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
.
p>
I see in your code :
newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;
检查 geselecteerdVoedsel
和 selDatum
不为零,或者它们被过度使用,并且完成为零。
如果它们是可选数据(但我不这么认为),请在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.
希望有帮助,
这篇关于核心数据保存错误(NSValidationErrorKey,Cocoa错误1570)保存NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!