In this CloudKit tutorial, youâll learn how to add and query data in iCloud from your app, as well as how to manage that data using the CloudKit dashboard.
Wonderful tutorial! Iâm learning a ton from it, beyond just the cloudkit portion. The sample code is great.
The one topic that I can follow in the code, but wouldnât have there on my own, is the âModelâ class.
Can you help me understand the rationale for it? Is it effectively always best practice to structure things this way when interacting with CloudKit data? Any articles or tutorials on the subject that would be good to read up on (searching hasnât turned up much!).
I have an issue running the app. My app wonât load a list of places from the database. Looks like the constructor for the Establishment class isnât actually parsing the CKRecord itâs being passed.
Why is âresultsâ assigned the type â[weak self]â and not âCKRecordâ?
I think Iâm getting my head around the Model (Apple recommendation to wrap the CK interactions, by the looks of it) - but now Iâm starting to play with adding notes to the app.
Iâve gotten to the point of creating a new note, and even populating the Establishment Record ID for that Note - but havenât cracked how to also append the new Note recordName to the Establishmentâs Reference (List) and am struggling to find examples. Any ideas @mkatz?
Hey @mechaamir, sorry for the delay, but for future reference on your question:
In Swift, this is actually a capture list, not typing the results to be CKRecord. Whenever you assign a closure to a property, and self is referenced in that closure, you actually create a strong reference cycle, and could have a memory leak. This allows values to be set to nil that might have been otherwise captured in the closure.
Does the issue still occur with the finished project for you?
Once you create a Note, youâll need to add the CKRecord.Reference of that note to the array of notes on Establishment. The true would be the same for the inverse: you need to add the Establishmentâs CKRecord.Reference to the Noteâs establishment field.