Beginning CloudKit - Part 4: Saving Records | Ray Wenderlich

In this video, learn all about the basics of saving your data to CloudKit using the convenience API.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4247-beginning-cloudkit/lessons/4

Hi Brian,

A quick question: What are the advantages of using enums vs. using structs for your constants?

@vegetarianzombie Do you have any feedback on this one? Thank you - much appreciated! :]

Hi Zombie,
No answer yet from Bryan.

Both are umbrellas, both provide type and both help keep your code structured.
But my take on this is that from a semantic point of view , I"ll go for enums.
(It is now the Ray Wenderlich recommended way)
Also using a caseless enum prevents you from creating an instance of that type.

Hey @vegetarianzombie - First, love the tutorials, been extremely helpful. You mention in Saving Data that you will cover modifying a RecordType. Iā€™ve watched a couple of times and canā€™t find it. Iā€™m using private data to hold a few fields for consistency across devices - I can save the initial values, query them, but canā€™t figure out how to modify and save. So I have the CRD part of CRUD, looking for the U. Thanks in advance.

Al

Thank you for great tutorial. My question is, how can I save an array of objects, entriesArray in my example :

class FS_Statement
{
ā€¦
var entriesArray: [FS_Entry] = [ ] //how to save this array?
}

class FS_Entry
{
var amount: FS_Amount? //or how would I save this object?
ā€¦
var subEntryArray: [FS_Entry] = [ ]
var type: FinancialEntryType = .parentEntry

}

class FS_Amount {
var _abs_value: Double?
var _isIncome: Bool?
}

In Firebase I just made a json dictionary of type AnyObject, but CloudKit doesnā€™t support it

Hi Brian,
Thank you very much for the great tutorial!

I have a question, Could you please say, can user delete saved data from CloudKit? I tried to delete data from settings, [Settings] ā†’ [iCloud] ā†’ [Manage Storage], but there is not my app in the ā€˜Manage storageā€™ list. Also it happened with Key-value storage. Must I do it only programmatically?

I donā€™t believe userā€™s have the ability to granularly delete data from cloudkit databases. Iā€™m pretty sure the only option is to opt-out or programmatically delete the info.

1 Like

Hey Brian,
can you explain what happens when the app is closed while records are being saved?

How can I guarantee that the update was successful?

I ask because when I want to save a new value on a record and the internet connection is poor at this moment, the upload might take some time. During this time the user closes the app. What happens then? (it is all asynchronous)

My idea to guarantee it is to store a ā€œsuccessfullySavedā€ variable that indicates whether the update was successful. I would set it to TRUE in the completion block of the saveRecord function. When the app enters the foreground again, I can check whether there are still updates pending.

Another solution would be long-lived operations. But in my opinion it is a overkill for uploading just one ā€œsmallā€ value.

Itā€™s been a long time since I worked with CloudKit. I never did tests to perform a query in the face of app shutdown. If the query is mission critical, then you should have your app perform some background processing. I hope that helps.

Thanks for you reply! Yes I think you are right. it is the best to perform background tasks when working with cloud kit. :slight_smile:

Just a quick bit of feedback. It is super confusing that Brian instructs us to use the AttendeeTableViewController, which is a class in the demo project, but itā€™s not in the Starter project.

It might be really helpful to just overdub this lesson and correct him to say ā€œSessionTableViewControllerā€ instead of ā€œAttendeeTableViewControllerā€. Just sayinā€™. :wink:

When I get to the challenge, I pause the video. However, itā€™s only until you get to the solution part of the video does it become clear that at some point the challenge uses SessionTableViewController, not AttendeeTableViewController.

Itā€™s a minor thing, but itā€™s just a little frustrating ā€“ and it held me up a bit, when Iā€™m trying to go through these tutorials as quickly as possibleā€¦ :+1:t2:

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Thanks for letting us know. Sometimes these things occur, especially when we do a refactor of an older project. Nice work making it through.

@vegetarianzombie The download materials donā€™t match what is in the videos.

This are some of the files are missing:

AttendeeTableViewController.swift
plist files

Can you please let me know here can I download the files are missing?

Screen Shot 2020-11-04 at 1.12.17 PM