Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
868 views
in Technique[技术] by (71.8m points)

xcode - Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) saving NSDate

I'm getting an error with saving to a Core data object in Xcode.

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.)

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]) {
...

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

So you can see that I put an NSDate into the 'datum' variable. But on execution I still get an error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

I see in your code :

newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;

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.

Hope this help,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...