I am using following code but I am getting errors.
"can not convert value of type NSURL to int32"
at this line:
if let fileHandle = NSFileHandle(fileDescriptor: fileurl, closeOnDealloc: &err).
and getting this error
"type of expression ambiguous without more context" at this line
if !data.writeToURL(fileurl, options: .DataWritingAtomic, error: &err)
Code:
let dir:NSURL = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.CachesDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).last as NSURL
let fileurl = dir.URLByAppendingPathComponent("log.txt")
let string = "\(NSDate())\n"
let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
if NSFileManager.defaultManager().fileExistsAtPath(fileurl.path!) {
var err:NSError?
if let fileHandle = NSFileHandle(fileDescriptor: fileurl, closeOnDealloc: &err) {
fileHandle.seekToEndOfFile()
fileHandle.writeData(data)
fileHandle.closeFile()
}
else {
print("Can't open fileHandle \(err)")
}
}
else {
var err:NSError?
if !data.writeToURL(fileurl, options: .DataWritingAtomic, error: &err) {
print("Can't write \(err)")
}
}