Swift Playground Read/Write File Permission Issue

Create a playground in my iOS project to do some data processing, and then write the result to a JSON file at somewhere in the project.

when I write file using the very common methods:

func write<T>(toFile path: T, atomically useAuxiliaryFile: Bool, encoding enc: Encoding) throws where T : StringProtocol

an error occurs :

error domain=nscocoaerrordomain code=513 "you don’t have permission to save the file

after some googling, still has no ideas why does it has no permission.

another project with playground in it, it works with no problems when writing files to folders in the project.

The difference between these two project is the platform, that’s a macOS project, and this is an iOS one.

So I think maybe this is the problem. And I inspect the playground, change the platform to macOS,

playground inspect

It works now!

amadman
amadman

iOS,macOS,Web,STM32,Unity3D,Blender,ML,AI

Articles: 12