简体   繁体   English

核心数据+ iCloud:iCloud存储仅增加而不减少

[英]Core data + iCloud:iCloud Storage only increase not decrease

I am writing an diary App with iCloud+Core data resolution.While my developing. 我正在编写具有iCloud + Core数据分辨率的日记应用程序。 I found that the iCloud Storage only increase even I try to delete my diary in my app .I use the one to many. 我发现即使尝试删除我的应用中的日记,iCloud存储也只会增加。我使用了很多。 one is the Diary(title,content,...) and the many is the Photos. 一本是日记(书名,内容等),另一本是照片。 At first, I create some diarys with some photo, then i delete some photos. 首先,我用一些照片创建一些日记,然后删除一些照片。 but the iCloud storage just increase,not decrease... After knowing this proble,i try to turn off the iCloud,switch the context to local Core Date Store,I found it doesn't has the proble i describe above . 但是iCloud的存储只是增加了,而不是减少了... 知道了这个问题后,我尝试关闭iCloud,将上下文切换到本地Core Date Store,我发现它没有上面描述的问题 I don't know why will this happen. 我不知道为什么会这样。 Please help me. 请帮我。 thank you. 谢谢。

Here is the core data Model 这是核心数据模型 在此处输入图片说明

Here is the output of SQL of Core Data when I delete the photo in iCloud Store. 当我在iCloud Store中删除照片时,这是Core Data的SQL输出。

2015-12-23 09:10:27.991 LPDiary[749:215074] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCONTENT, t0.ZDIARYID, t0.ZLOCATION, t0.ZNOTEPAPERNAME, t0.ZRESERVEBINARYDATA1, t0.ZRESERVEBINARYDATA2, t0.ZRESERVEDATE1, t0.ZRESERVEDATE2, t0.ZRESERVESTR1, t0.ZRESERVESTR2, t0.ZTYPE, t0.ZWEATHER, t0.ZWRITEDATE FROM ZLCLDIARY t0 WHERE  t0.ZDIARYID = ? ORDER BY t0.ZWRITEDATE DESC
2015-12-23 09:10:27.992 LPDiary[749:215074] CoreData: annotation: sql connection fetch time: 0.0009s
2015-12-23 09:10:27.992 LPDiary[749:215074] CoreData: annotation: total fetch execution time: 0.0013s for 1 rows.
2015-12-23 09:10:27.995 LPDiary[749:215074] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZIMAGEDATA, t0.ZORDER, t0.ZRESERVESTR1, t0.ZOWNER, t0.Z1PHOTOS FROM ZLCLPHOTO t0 WHERE  t0.Z_PK IN  (?)  
2015-12-23 09:10:27.997 LPDiary[749:215074] CoreData: annotation: sql connection fetch time: 0.0017s
2015-12-23 09:10:27.997 LPDiary[749:215074] CoreData: annotation: total fetch execution time: 0.0026s for 1 rows.
2015-12-23 09:10:28.000 LPDiary[749:215074] CoreData: sql: BEGIN EXCLUSIVE
2015-12-23 09:10:28.000 LPDiary[749:215074] CoreData: sql: DELETE FROM ZLCLPHOTO WHERE Z_PK = ? AND Z_OPT = ?
2015-12-23 09:10:28.007 LPDiary[749:215074] CoreData: sql: UPDATE ZLCLDIARY SET Z_OPT = ?  WHERE Z_PK = ? AND Z_OPT = ?
2015-12-23 09:10:28.008 LPDiary[749:215074] CoreData: sql: UPDATE Y_UBMETA set YPEERID="mobile~5C6B0588-0876-42C4-88CA-2FC85745ED66", YTRANSACTIONNUMBER=30 WHERE YPEERID="mobile~5C6B0588-0876-42C4-88CA-2FC85745ED66"
2015-12-23 09:10:28.046 LPDiary[749:215074] CoreData: sql: COMMIT
2015-12-23 09:10:28.061 LPDiary[749:215074] CoreData: sql: select YPEERID, YTRANSACTIONNUMBER, Y_PK from Y_UBMETA

Core Data without iCloud works as you might expect. 不使用 iCloud的核心数据可以按您期望的那样工作。 When you add data, the persistent store gets larger, and when you delete data it gets smaller. 添加数据时,持久性存储会变大,而删除数据时,持久性存储会变小。

Core Data with iCloud works by creating a baseline data store and then adding transaction logs that modify the baseline. iCloud的核心数据通过创建基准数据存储,然后添加修改基准的事务日志来工作。 When you add data, there's a new transaction that says to add the data. 当您添加数据时,会有一个新事务显示要添加数据。 When you delete data, there's a new transaction that says to delete the data. 删除数据时,会有一个新事务显示要删除数据。 But the transaction doesn't actually delete the data-- it just says that the data should be deleted, so that when transactions are replayed, the data is removed. 但是事务实际上并没有删除数据,它只是说应该删除数据,以便在重播事务时删除数据。

At some point Core Data is supposed to condense all of the transactions into a new baseline. 在某个时候,Core Data应该将所有事务压缩到一个新的基准中。 Deleted data would be removed at that point. 届时将删除已删除的数据。 However Apple doesn't document when this happens, and I'm not sure that it ever does happen. 但是,Apple不会在发生这种情况时进行记录,而且我不确定它是否会发生。

That's why you see different results depending on whether iCloud is enabled for Core Data. 因此,根据是否为核心数据启用了iCloud,您会看到不同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM