gpt4 book ai didi

ios - 快速在文本文件末尾 append 一些文本

转载 作者:行者123 更新时间:2023-11-28 10:19:35 26 4
gpt4 key购买 nike

<分区>

我正在使用以下代码,但出现错误。

"can not convert value of type NSURL to int32"

在这一行:

if let fileHandle = NSFileHandle(fileDescriptor: fileurl, closeOnDealloc: &err).

出现这个错误

"type of expression ambiguous without more context" at this line

if !data.writeToURL(fileurl, options: .DataWritingAtomic, error: &err)

代码:

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)")
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com