I touch
ed a file in my home directory, myFile.txt
, and changed its permissions.
touch ~/myFile.txt
chmod a+rwx ~/myFile.txt
I'd like to write to this file from the XCode Playground,
import Cocoa
let someText = NSString( string:"some text" )
let destinationPath = "/Users/connorjohnson/myFile.txt"
var filemgr = NSFileManager.defaultManager()
do {
try someText.writeToFile(destinationPath, atomically: true, encoding: NSUTF8StringEncoding)
} catch let error as NSError {
print("Error: \(error)")
}
But I keep getting this error:
"Error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “myFile.txt” in the folder “connorjohnson”." UserInfo={NSFilePath=/Users/connorjohnson/myFile.txt, NSUnderlyingError=0x7f91e9725890 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}\n"
Is there a way to write to a file in my home directory? Or is this a built-in security feature? I compiled a Swift2 script to write to a file in my home directory and it worked just fine. Thanks!