1 Reply
      Latest reply on Nov 21, 2019 1:26 AM by eskimo
      SyamalaDutt Level 1 Level 1 (0 points)

        I am using below piece of code to delete a file



        if FileManager.default.fileExists(atPath: Path)
                                try FileManager.default.removeItem(atPath: Path)

        Path is /Library/LaunchAgents/com.example.agent.plist


        I am getting below error



        Error Domain=NSCocoaErrorDomain Code=513 "“com.example.agent.plist” couldn’t be removed because you don’t have permission to access it." UserInfo={NSFilePath=/Library/LaunchAgents/com.example.agent.plist, NSUserStringVariant=(


        ), NSUnderlyingError=0x600000c76af0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}



        How can i delete a file with admininistrative priveleges from swift.

        Is there a way i can do without involving apple scripts and shell scripts using native swift?