Caleb Caleb - 1 year ago 87
Swift Question

How to save a CKRecord to CloudKit with multiple type of information with Swift

If I was trying to save a CKRecord that had a title(String) and a Location(CLLocation) together so that when they were fetched, they would be downloaded as a pair would they both be in the same record or is there a better way to do it?

Answer Source

Creating a record that contains both fields would be the appropriate way to do it.

CloudKit allows multiple fields of various types to exist in one record type. Here's an example of the CloudKit dashboard showing a record type with both a string and a location:

enter image description here

To save your record, you would do something like this:

myRecord["TestString"] = title as CKRecordValue
myRecord["TestLocationCoords"] = location as CKRecordValue

Where title is a String and location is a CLLocation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download