2015-03-10 2 views
0

Целью является создание многомерного массива для всего содержимого текстового файла, который будет импортирован в CoreData.Добавить данные в словарь array

В текстовом файле есть разделы, а по разделам - строки с атрибутами таблицы и значения. В разделе «По умолчанию» в коммутаторе приведен краткий пример.

я получил следующее сообщение об ошибке:

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-массив?

ответ

1

Поскольку stringArrayCompleteData определяется как Dictionary<String, Dictionary<String, Any>>, вам нужно добавить пару ключ-значение, как это:

stringArrayCompleteData[arrIndexSection] = [arrSingleRow[0]: arrSingleRow[1]] 
Смежные вопросы