2016-04-14 62 views
0

我一直在試圖找到一種方法,通過swift 2和Xcode 7連接到我的網絡驅動器。我可以連接到我的桌面或文檔目錄,但不能連接到我的服務器。我玩過NSString/NSURL等,但無濟於事。以下是我的參考代碼:迅速連接到網絡smb驅動器

//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 

任何幫助,將不勝感激。

+0

從smb獲取文件的運氣? – perwyl

回答

0

它看起來像您將文件名附加到已包含文件名的路徑(「smb://path/to/text/file/on/network/server/myTextFile.txt」+「myTextFile。 txt「=」smb://path/to/text/file/on/network/server/myTextFile.txtmyTextFile.txt「)