Основные данные не сохраняют NSString

В настоящее время наблюдается проблема с сохранением моих основных данных. По какой-то причине NSString не сохраняется должным образом, всегда возвращая 0. Ниже мой текущий код.

appDelegate =(NotaciousAppDelegate *) [[UIApplication sharedApplication] delegate];

        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];
        NSArray *fetchedNotes;

        NSArray *notes = [object valueForKey:@"result"];
        for (NSDictionary *singleNote in notes){

            noteFetch=[[NSFetchRequest alloc] init];
            [noteFetch setEntity:entity];
            NSPredicate *pred=[NSPredicate predicateWithFormat:@"ID==%@",[singleNote objectForKey:@"note id"]];
            [noteFetch setPredicate:pred];

            NSError *fetchError=nil;
            fetchedNotes=[appDelegate.managedObjectContext executeFetchRequest:noteFetch error:&fetchError];

            if (fetchError!=nil) {
                NSLog(@"syncNotes fetchError=%@,details=%@",fetchError,fetchError.userInfo);
            }
            if ([fetchedNotes count]==0) {


                NSString *notelocked = [singleNote objectForKey:@"note locked"];

                NSString *notecreated = [singleNote objectForKey:@"note created"];
                NSString *noteupdated = [singleNote valueForKey:@"note updated"];
                NSString *notetitle = [singleNote objectForKey:@"note title"];
                NSString *notesummary = [singleNote objectForKey:@"note summary"];
                NSString *noteid = [singleNote objectForKey:@"note id"];
                NSString *notecontent = [singleNote objectForKey:@"note content"];

                NSString *formattedTitle = [NSString decodeShit:notetitle];
                NSString *formattedSummary = [NSString decodeShit:notesummary];
                NSString *formattedContent = [NSString decodeShit:notecontent];


                NSLog(@"Note Title: %@",formattedTitle);
                NSLog(@"Note Summary: %@",formattedSummary);
                NSLog(@"Note ID: %@",noteid);
                NSLog(@"Note Content: %@",formattedContent);
                NSLog(@"Note Created: %@",notecreated);
                NSLog(@"Note Updated: %@",noteupdated);
                NSLog(@"Note Locked: %@",notelocked);

                newNote = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];
                [newNote autorelease];

                [newNote setValue:formattedContent forKey:@"content"];
                [newNote setValue:formattedSummary forKey:@"summary"];
                [newNote setValue:formattedTitle forKey:@"title"];
                [newNote setValue:noteid forKey:@"ID"];
                [newNote setValue:notecreated forKey:@"created"];
                [newNote setValue:noteupdated forKey:@"updated"];
                [newNote setValue:notelocked forKey:@"locked"];

                NSLog(@"Note Updated in MOC:%@",[newNote valueForKey:@"updated"]);

                NSError *error = nil;
                if (![appDelegate.managedObjectContext save:&error]) {
                    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
                    abort();
                }


            }

            [noteFetch release];

        }

Проблема возникает при попытке сохранить обновленную строку. По какой-то причине, независимо от того, какая строка там находится, она не будет сохранена в атрибуте Core Data.

Я изо всех сил пытаюсь найти какую-либо внятную причину, по которой это не может быть сохранено, но я собираюсь счесть это возможным. Это последняя проблема, которую необходимо решить, прежде чем это приложение попадет на полки. Любая помощь будет здорово!

Изменить

Ошибки нет, только следующий вывод в консоли отладки.

 2011-04-24 10:53:22.815 Notacious[5660:707] Note Title: Hello there!
 2011-04-24 10:53:22.816 Notacious[5660:707] Note Summary: 
 2011-04-24 10:53:22.817 Notacious[5660:707] Note ID: 1240
 2011-04-24 10:53:22.817 Notacious[5660:707] Note Content: Hello there!

 This is a new note made from the iPhone client. Woot?
 2011-04-24 10:53:22.818 Notacious[5660:707] Note Created: Thu Apr 21 19:19:39 -0700 2011
 2011-04-24 10:53:22.819 Notacious[5660:707] Note Updated: Thu Apr 21 19:19:39 -0700 2011
 2011-04-24 10:53:22.820 Notacious[5660:707] Note Locked: 0
 2011-04-24 10:53:22.823 Notacious[5660:707] Note Updated in MOC:0

person Sebastien Peek    schedule 24.04.2011    source источник
comment
Вы видите что-нибудь ошибочное?   -  person Kendall Helmstetter Gelner    schedule 24.04.2011
comment
Добавил вывод из консоли в вопрос.   -  person Sebastien Peek    schedule 24.04.2011


Ответы (2)


Вы действительно уверены, что «примечание обновлено» в словаре не является NSDate, а не NSString? Вывод журнала выглядит УЖАСНО, как будто у вас есть NSDate.

Вам нужно будет использовать NSDateFormatter, чтобы сохранить его в свойстве объекта NSString, если это так.

person Kendall Helmstetter Gelner    schedule 24.04.2011
comment
Это правда, что это NSDate. Однако происходит еще одна странная вещь: почему созданная заметка может быть сохранена, а не обновлена. Они оба NSStrings хранятся в двух разных атрибутах NSString... - person Sebastien Peek; 24.04.2011
comment
Я не уверен, почему это работает, но я уверен, что это источник проблемы. - person Kendall Helmstetter Gelner; 24.04.2011
comment
Хорошо, обновлю, чтобы включить NSDateFormatter, чтобы я мог правильно сохранить строку. Вернется к вам. - person Sebastien Peek; 24.04.2011
comment
Сделал все вышеперечисленное и все равно ничего не сохраняется. - person Sebastien Peek; 24.04.2011
comment
Хм, извините - не знаю, что еще попробовать. Вы можете попробовать запустить mogenerator на своей объектной модели, чтобы увидеть, есть ли у нее какие-либо предупреждения о проверке. Это сторонний инструмент, который вы должны загрузить. - person Kendall Helmstetter Gelner; 24.04.2011

Следующий код сработал.

appDelegate =(NotaciousAppDelegate *) [[UIApplication sharedApplication] delegate];

        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];
        NSArray *fetchedNotes;

        NSArray *notes = [object valueForKey:@"result"];
        for (NSDictionary *singleNote in notes){

            noteFetch=[[NSFetchRequest alloc] init];
            [noteFetch setEntity:entity];
            NSPredicate *pred=[NSPredicate predicateWithFormat:@"ID==%@",[singleNote objectForKey:@"note id"]];
            [noteFetch setPredicate:pred];

            NSError *fetchError=nil;
            fetchedNotes=[appDelegate.managedObjectContext executeFetchRequest:noteFetch error:&fetchError];

            if (fetchError!=nil) {
                NSLog(@"syncNotes fetchError=%@,details=%@",fetchError,fetchError.userInfo);
            }
            if ([fetchedNotes count]==0) {

                NSString *notelocked = [singleNote objectForKey:@"note locked"];

                NSString *noteupdated = [singleNote valueForKey:@"note updated"];
                NSString *notecreated = [singleNote objectForKey:@"note created"];
                NSString *notetitle = [singleNote objectForKey:@"note title"];
                NSString *notesummary = [singleNote objectForKey:@"note summary"];
                NSString *noteid = [singleNote objectForKey:@"note id"];
                NSString *notecontent = [singleNote objectForKey:@"note content"];

                NSString *formattedTitle = [NSString decodeShit:notetitle];
                NSString *formattedSummary = [NSString decodeShit:notesummary];
                NSString *formattedContent = [NSString decodeShit:notecontent];

                newNote = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];

                [newNote setValue:formattedContent forKey:@"content"];
                [newNote setValue:formattedSummary forKey:@"summary"];
                [newNote setValue:formattedTitle forKey:@"title"];
                [newNote setValue:noteid forKey:@"ID"];
                [newNote setValue:notecreated forKey:@"created"];
                [newNote setValue:noteupdated forKey:@"noteupdated"];
                [newNote setValue:notelocked forKey:@"locked"];

                NSError *error = nil;
                if (![appDelegate.managedObjectContext save:&error]) {
                    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
                    abort();
                }


            }

            [noteFetch release];

        }

Кажется, CoreData не понравилось, что я обращаюсь к атрибуту с именем updated.

person Sebastien Peek    schedule 28.04.2011