I have a function to input a users name into a new recordName in CloudKit (shown below), however I also need to add the users 'score' into the same record.
Is there a way to insert another field "usersScore" by referencing its unique 'recordName' value?
/// INSERT NEW ENTRY TO DB.
func insertName(nameEntry: String) -> CKRecordID {
// Connects to the user database table.
let userTable = CKRecord(recordType: "User")
// Connects the Database to the public container.
let publicData = CKContainer.default().publicCloudDatabase
// Adds the users entry into the "name" field.
userTable["name"] = nameEntry as NSString
// If the record has saved or an error has occurred.
publicData.save(userTable) { (record, error) in
if let saveError = error {
//Error.
print("An error occurred in \(saveError)")
}else {
// Success.
print("Saved Record!")
}
}
// RecordName (ID) of the current user.
recordNameID = userTable.recordID
return recordNameID!
}
To enter multiple records it's better to use
CKModifyRecordsOperation
. Here's how I did it...