![](/img/trans.png)
[英]iOS Webkit not working on device, but works on simulator at swift
[英]writeToFile is working on simulator and not working on device using ios swift
if let filepath = NSBundle.mainBundle().pathForResource(“abc”, ofType: "txt")
{
var test_string=“abcd”
let fileContent:NSData= test_string.dataUsingEncoding(NSUTF8StringEncoding)!
fileContent.writeToFile(filepath, atomically: true)
let contents = try NSString(contentsOfFile: filepath, usedEncoding: nil) as String
print("file content : "+contents)
}
catch
{
self.view.makeToast("write to file error")
}
選中從文本文件讀取和寫入數據 。
我認為您的問題是路徑,因為模擬器文件夾可以在任何位置,但對於設備編號則更好,最好將文件保存在應用程序本身的文件夾內。
而且,如果您正在編寫文本,則可以編寫try test_string.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.