Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 快速连接到网络smb驱动器_Xcode_Swift - Fatal编程技术网

Xcode 快速连接到网络smb驱动器

Xcode 快速连接到网络smb驱动器,xcode,swift,Xcode,Swift,我一直在尝试通过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://

我一直在尝试通过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")

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

从smb获取文件有没有运气?从smb获取文件有没有运气?