Steve
Steve

Reputation: 1153

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?

Upvotes: 0

Views: 414

Answers (1)

Anthony C
Anthony C

Reputation: 1990

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.

Upvotes: 4

Related Questions