I have created an app using Swift 3 and Xcode 8.3.3 that records audio files and saves them to the app's Document directory. I would now like to save these files to iCloud to have them backed up. I have been able to save a simple record to iCloud using this code:
let database = CKContainer.default().publicCloudDatabase
func saveToCloud(myContent: String){
let myRecord = CKRecord(recordType: "AudioRecording")
myRecord.setValue(myContent, forKey: "content")
database.save(myRecord) { (record, error) in
print(error ?? "No error")
guard record != nil else {return}
print("Saved record to iCloud")
}
}
It seems like I should just need to add a line of code that would look something like this:
newNote.setValue(audioObject, forKey: "Audio")
But I'm not sure what object I need to pass it for audioObject and if iCloud will be able to handle the object. Any suggestions?