目的是为文本文件的整个内容创建一个多维数组,该数组将导入到CoreData中。
文本文件有部分,部分下面是具有表和值属性的行。在交换机的默认值下,是一个简短的示例。
我收到以下错误:
找不到会员'下标'
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)
}
}
}
如何将“default”中的行添加到CompleteData-Array?
答案 0 :(得分:1)
由于stringArrayCompleteData
定义为Dictionary<String, Dictionary<String, Any>>
,您需要添加一个键值对,如下所示:
stringArrayCompleteData[arrIndexSection] = [arrSingleRow[0]: arrSingleRow[1]]