gpt4 book ai didi

xcode - 快速连接到网络 smb 驱动器

转载 作者:行者123 更新时间:2023-11-28 08:40:33 31 4
gpt4 key购买 nike

我一直在尝试找到一种通过 swift 2 和 Xcode 7 连接到我的网络驱动器的方法。我可以连接到我的桌面或文档目录,但不能连接到我的服务器。我玩过 NSString/NSURL 等但无济于事。以下是我的代码供引用:

//Target file
let myFile = "myTextFile.txt"

// Write this text.
let myText = "Dante, The Divine Comedy"

//Target path
if let myDir : NSString = ("smb://path/to/text/file/on/network/server/myTextFile.txt") {
let myPath = myDir.stringByAppendingPathComponent(myFile);

// Writting
do {
try myText.writeToFile(myPath, atomically: true, encoding: NSUTF8StringEncoding)
} catch let error as NSError {
print("Failed writing to URL: \(myPath), Error: " + error.localizedDescription)
}

//Reading
do {
let myText = try? NSString(contentsOfFile: myPath, encoding: NSUTF8StringEncoding)
} catch let error as NSError {
print("Failed writing to URL: \(myPath), Error: " + error.localizedDescription)
}
} //closes if

如有任何帮助,我们将不胜感激。

最佳答案

看起来您正在将文件名附加到已经包含文件名的路径 ("smb://path/to/text/file/on/network/server/myTextFile.txt"+ "myTextFile.txt "= "smb://path/to/text/file/on/network/server/myTextFile.txtmyTextFile.txt")

关于xcode - 快速连接到网络 smb 驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631721/

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