【问题标题】:CoreData Relationship Contents not persistingCoreData 关系内容不持久
【发布时间】:2015-03-15 13:16:56
【问题描述】:

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

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

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

【问题讨论】:

  • 我还检查了 bookEntity 不是 null 或空

标签: ios iphone core-data


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    相关资源
    最近更新 更多