IOS swift: save cache using coredata (cloud)

I learned to use cloudkit to save and retrieve records, but I was confused about saving the cache in coredata.

For example, I extracted several records and displayed several attributes of this type of record (say, A, C, and F) using a table. And when I click on the cell, it will show this entry (all attributes of this entry: ABCDEF, but not including the entry of reference attributes). I was wondering if these things should be stored in coredata when I first took the record: "ACF and recordID"? And when the user clicks to see the details, do I get again using recordID? And the key point is, what type of attribute should I use to store CKRecordID / CKRecord?

I know that I could store things like the image in a local cache file (also confusing ..), but is this not a permanent store? And the reason why I did not store the record of all attributes directly is that this record is an โ€œinvitationโ€ only if the user decides to accept it, it will load all attributes, including attributes of the reference type. Any help would be helpful, thanks!

+1
source share
1 answer

You should only archive system fields during caching, for example:

private func dataFromRecord(record:CKRecord) -> NSData{ let archivedData = NSMutableData() let archiver = NSKeyedArchiver(forWritingWithMutableData: archivedData) archiver.requiresSecureCoding = true record.encodeSystemFieldsWithCoder(archiver) archiver.finishEncoding() return archivedData } private func recordFromData(archivedData:NSData) -> CKRecord?{ let unarchiver = NSKeyedUnarchiver(forReadingWithData: archivedData) unarchiver.requiresSecureCoding = true let unarchivedRecord = CKRecord(coder: unarchiver) return unarchivedRecord } 

31:10 WWDC 2015 - Session 715 - iOS, OS X enter image description here

+9
source

Source: https://habr.com/ru/post/983932/


All Articles