How to save a file to icloud

Store your files in iCloud and save space on your device
Add your Desktop and Documents filestoiCloud Drive. Now you can get the files from your Mac Desktop and your Documents folder on all of your devices with iCloud Drive.

How to save your Desktop and Documents folder to iCloud Drive
With Desktop & Documents Folders iCloud Drive syncing enabled, every photo, file, and folder you save to your desktop will automatically save in iCloud, where you can access it

How to Save to Mac Instead of iCloud on a Per-Save Basis
If you’d rather save to your Mac rather than iCloud, here is howto change it per-save and also two different ways to change the default behavior

How to Save Documents to iCloud on iPhone/Mac/PC
How about save documents toiCloud from PC/Mac? In order to take full advantage of the iCloud service, you can also share information across the different platforms.

How to Manage iCloud on Sierra: Saving and Deleting Files
Howtosave documents toiCloud storage. iCloud can and should be used as any other folder you’ve got on Mac. For instance, to upload filestoiCloud Drive you simply take the files you need (be it images, documents, any other file) and drag them directly to the open iCloud folder.

How do I permanently save a file to iCloud using FileManager using...
When I saveafiletoiCloud, when the app shuts down, the file is not there anymore. Here is my code before the app shuts down with the print results in comments beside the print statements: FileManager.default.createFile(atPath: saveToURL.path, contents: dataImage, attributes: nil).