Я не знаю, где я ошибаюсь, здесь вывод консоли
2011-10-07 11:03:29.508 Golden Corral[2365:207] After whole process Name : Ggggggggggg
2011-10-07 11:03:29.513 Golden Corral[2365:207] After whole process Score : 27600
2011-10-07 11:03:29.515 Golden Corral[2365:207] Error : Error Domain=NSCocoaErrorDomain Code=1660 "The operation couldn’t be completed. (Cocoa error 1660.)" UserInfo=0x5566d60 {NSValidationErrorObject=<HighScore: 0x5563eb0> (entity: HighScore; id: 0x5555ed0 <x-coredata:///HighScore/tDAD877F0-0594-4E14-819F-AF5BDA4A38A82> ; data: {
PlayerName = Ggggggggggg;
TopTenScore = 27600;
}), NSValidationErrorKey=PlayerName, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1660.), NSValidationErrorValue=Ggggggggggg}
, и вот мой код сохранения данных.Я проверяю, вводит ли пользователь свое имя для рекорда или нет, если я не принимаю имя Anonymous, за исключением того, что ввел пользователь.GDB показывает правильное значение как имени пользователя, так и highScore, но данные не хранятся в базе данных.
-(void)calculateHighScore
{
////////////////////////// Core Data Entries. ///////////////
HighScore *ScoreData = (HighScore*)[NSEntityDescription insertNewObjectForEntityForName:@"HighScore" inManagedObjectContext:self.managedObjectContext];
if ([txtName.text isEqualToString:@""] || [txtName.text length] == 0 )
{
NSLog(@"The Name :%@",txtName.text);
NSLog(@"%d",CountHighScore);
ScoreData.PlayerName = @"Anonymous";
ScoreData.TopTenScore = [NSNumber numberWithInt:CountHighScore];
NSLog(@"The Name :%@",ScoreData.PlayerName);
NSLog(@"%d",CountHighScore);
isWinner = NO;
levelCount ++;
}
else
{
NSLog(@"Befor Text assign highscore :%d",CountHighScore);
//CountHighScore = [txtName.text intValue];
ScoreData.PlayerName = txtName.text;
ScoreData.TopTenScore = [NSNumber numberWithInt:CountHighScore];
NSLog(@"The Name :%@",txtName.text);
NSLog(@"%d",CountHighScore);
isWinner = NO;
levelCount ++;
}
NSLog(@"After whole process Name : %@",ScoreData.PlayerName);
NSLog(@"After whole process Score : %d",CountHighScore);
// Code for inserting into DataBase
NSError *CorrectError;
if (![self.managedObjectContext save:&CorrectError])
{
// Handle the error...
NSLog(@"Error : %@",CorrectError);
}
}