目的是为文本文件的全部内容创建一个多维数组,将导入到 CoreData 中。
文本文件有节,节下是具有表属性和值的行。在开关的默认下,是一个简短的示例。
我收到以下错误:
Could not find member 'subscript'
var stringArray = fullImportContent!.componentsSeparatedByString("\n")
var stringArrayCompleteData = Dictionary<String, Dictionary<String, Any>>()
var arrIndexSection : String
for singleRow in stringArray
{
if(singleRow != "")
{
switch singleRow {
case "#Header":
arrIndexSection = singleRow
case "#Objekt":
arrIndexSection = singleRow
case "#Baustelle":
arrIndexSection = singleRow
case "#Auftraggeber":
arrIndexSection = singleRow
case "#Architekt":
arrIndexSection = singleRow
case "#Vermittler":
arrIndexSection = singleRow
case "#Kontaktstellen":
arrIndexSection = singleRow
case "#Dateien":
arrIndexSection = singleRow
default:
//Here the multiple array would be filled
var arrSingleRow = singleRow.componentsSeparatedByString(";")
/*
Example how the Context could be in the textfile
#Objekt
Objektnr; 1000000;
*/
stringArrayCompleteData += [arrIndexSection][arrSingleRow[0]][arrSingleRow[1]]
println(singleRow)
}
}
}
如何将“默认”中的行添加到 CompleteData 数组?
最佳答案
自 stringArrayCompleteData
定义为 Dictionary<String, Dictionary<String, Any>>
,你需要像这样添加一个键值对:
stringArrayCompleteData[arrIndexSection] = [arrSingleRow[0]: arrSingleRow[1]]
关于ios - 向字典数组添加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28958229/