CoreData关系内容不持久

时间:2015-03-15 13:16:57

标签: ios iphone core-data

enter image description here

我有以下关系,图书实体工作正常。但是,当我尝试提供关系并将其添加到心愿单时,该值不会持续存在,只能暂时使用。

这是我如何添加关系的代码

WishListBooks *wishList = [NSEntityDescription insertNewObjectForEntityForName:@"WishListBooks" inManagedObjectContext:[self getCoreDataContext]];

[wishList addContainsObject:self.bookEntity];


NSError *saveError;

if (![[self getCoreDataContext] save:&saveError]) {
    NSLog(@"Saving changes to book book two failed: %@", saveError);
} else
{
    NSLog(@"Data Saved onto Coredata");
}

但是当我打印日志时,我得到了。

<_PFArray 0x79f31bf0>(
<WishListBooks: 0x79fc1730> (entity: WishListBooks; id: 0x79f9a3e0 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p1> ; data: <fault>),
<WishListBooks: 0x79fbe6f0> (entity: WishListBooks; id: 0x79f2a390 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p2> ; data: <fault>),
<WishListBooks: 0x79fb33d0> (entity: WishListBooks; id: 0x79fb4250 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p3> ; data: <fault>),
<WishListBooks: 0x79f34cd0> (entity: WishListBooks; id: 0x79fc5520 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p4> ; data: <fault>),
<WishListBooks: 0x79fb73e0> (entity: WishListBooks; id: 0x79fc5530 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p5> ; data: <fault>),
<WishListBooks: 0x79f35ae0> (entity: WishListBooks; id: 0x79fb1e50 <x-coredata://150C6D01-71AB-4324-B5F4-9D553630C985/WishListBooks/p6> ; data: <fault>)
)

1 个答案:

答案 0 :(得分:1)

您所看到的是核心数据错误。这些不是错误,并不表示未保存关系数据。当Core Data从持久性存储加载数据时,它会将其作为错误加载,这意味着它是一个未加载其属性值的占位符对象。如果您尝试使用这些属性值,则会按需加载它们。这完全正常 - 在你的问题中,该消息实际上没有任何错误的迹象。

相关问题