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