我运行我的应用程序,然后获取我的数据。数据还可以。当我第二次跑步时,我的旧价值出现了问题。怎么了?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]];
for (int i =0; i<2; i++)
{
Test *test = [[[Test alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]] autorelease];
test.text = @"Text";
test.index = [NSNumber numberWithInt:i];
}
[self saveContext];
}
-(void) showValues
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Test" inManagedObjectContext:[self managedObjectContext]];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entity];
NSError *error;
NSArray *array = [[self managedObjectContext] executeFetchRequest:request error:&error];
NSLog(@"Array: %@ ", array);
}
首次运行
2012-01-22 21:48:52.092 Mew[411:707] Array: (
"<Test: 0x183f60> (entity: Test; id: 0x1856b0 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p1> ; data: {\n index = 0;\n text = Text;\n})",
"<Test: 0x184940> (entity: Test; id: 0x1857e0 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p2> ; data: {\n index = 1;\n text = Text;\n})"
)
第二次运行//第一个和第二个值是错误
2012-01-22 21:50:29.892 Mew[429:707] Array: (
"<Test: 0x16c950> (entity: Test; id: 0x16c720 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p1> ; data: <fault>)",
"<Test: 0x16d130> (entity: Test; id: 0x16c730 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p2> ; data: <fault>)",
"<Test: 0x1684c0> (entity: Test; id: 0x16bfd0 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p3> ; data: {\n index = 0;\n text = Text;\n})",
"<Test: 0x16ab90> (entity: Test; id: 0x16c100 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p4> ; data: {\n index = 1;\n text = Text;\n})"
)
答案 0 :(得分:14)
<fault>
并不意味着您的数据已损坏。这意味着它与获取的结果动态链接,并且在尝试访问对象的任何值/属性时将加载实际对象。记得 - 你在.m文件中使用了@dynamic?
当您访问对象的任何属性<fault>
NSLog
数组和故障消失时,它就会显示NSLog(@"Test: %@ ", test.text);
答案 1 :(得分:0)
我修复了一个错误。
我刚从
改变 NSLog(@"Array: %@ ", array);
到
for (Test *test in array)
{
NSLog(@"Test: %@ ", test.text);
}
故障消失了