ludluck ludluck - 1 month ago 11
Swift Question

How do you use the function createFile?

I found this declaration in Apple's API reference but I'm not sure how to use it.

func createFile(atPath path: String, contents data: Data?, attributes attr: [String : Any]? = nil) -> Bool


When I start typing
createFile
, there is no auto-complete that resembles this declaration either.

My path is a directory on my computer (not including the file's name), and the data is a string.

Answer

It works fine on my machine. You probably just aren't using a FileManager object:

enter image description here

However:

My path is a directory on my computer

Then you won't be able to write to it. How can an iPhone app see your computer? That makes no sense.