所以發生什麼事是當程序試圖訪問我炸燬的txt文件的其他2行時,當我查看數組下的xcode時,它顯示行被分隔「\ t」,但它不會顯示其他2行,以及它的瘋狂......請看我的代碼下面的任何幫助表示讚賞。致命錯誤:索引超出範圍Swift 3.1
var dictDoc = [String:String]()
var docArray = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
let path = Bundle.main.path(forResource: "docs", ofType: "txt")
let fileMgr = FileManager.default
if fileMgr.fileExists(atPath: path!){
do{
let fullText = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
let readings = fullText.components(separatedBy: "\n") as [String]
for i in 1..<readings.count {
let docData = readings[i].components(separatedBy: "\t")
dictDoc["Program"] = "\(docData[0])"
dictDoc["Signature"] = "\(docData[1])"
dictDoc["Extension"] = "\(docData[2])"
docArray.add(dictDoc)
}
}catch let error as NSError{
print("Error: \(error)")
}
self.title = "Word Processor Programs"
}
tableView.dataSource = self
tableView.delegate = self
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return docArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let doc = docArray[indexPath.row]
cell.textLabel?.text = "\((doc as AnyObject).object(forKey: "Program")!)"
cell.detailTextLabel?.text = "\((doc as AnyObject).object(forKey: "Signature")!) \((doc as AnyObject).object(forKey: "Extension")!)"
return cell
}
@IBAction func Closebtn(_ sender: UIButton) {
}
你可以發佈你正在試圖打破成組件的文本? – ebby94
方案\t Signautre \t擴展 字2.0 \t DB A5 2D 00 \t DOC MS酒吧子報頭\t FD 37 7A 58 5A 00 \t PUB Acrobat插件在\t 4D 5A 90 00 03 00 00 00 \t API MS酒吧 BDR WP DIC \t 43 42 46 49 4C 45 \t CBD 同桌文件\t 0D 44 4F 43 \t DOC 完美的辦公文檔\t CF 11 E0 A1 B1 1A E1 00 \t DOC 字d OC子頭\t EC A5 C1 00 \t DOC MS關閉文檔\t D0 CF 11 E0 A1 B1 1A E1 \t DOC | DOT | PPS | PPT –
它失去了格式化,但多數民衆贊成在樣品 –