Group Group Group Group Group Group Group Group Group

Icloud - read contents of url

Is it possible to read contents of an url from a file on iCloud Drive? When I try to read it returns a string that has been converted to binary? or when I do it base64string it converts it to something different also. I wrote a simple file that has just text “This is a test.” and it keeps converting to something different. I’ve also tried utf8 encoding on my file but then on the test string there is no encoding just text. Is security stoping this? I’m also doing startAccessingSecurityScopedResource() before the read. Please help or suggest.

Hey Lewis,

What I’m asking is how do you do it swift programmatically. I want to read the contents of url or file. I’m saving a progress in an application and then exporting in form of a file (base64) and uploading to iCloud and then I’m a importing via a swift application to read contents of url or file to bring into the swift application to open.

Hi @dbozeman,
Data that is returned from an URL is generally is binary Data format.

If you want to convert this into string (if it is convertible to string), you can use

let str = String(data: data, encoding: .utf8)

where data is the binary data that you got from the url.


Hi @dbozeman,
if there is more to your question, you might want to post some code to demonstrate what you are doing and where the problem is.

You can also have a look at this