0

The aim is to create a multidimensional array for the whole content of a textfile, which would be imported into CoreData.

The textfile have sections and under the sections are the the rows with the attributes of the table and value. Under Default in the switch, is a short Example of it.

I got the following error:

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)
        }
    }
}

How can i add the row in the "default" to the CompleteData-Array?

1 Answer 1

0

Since stringArrayCompleteData is defined as Dictionary<String, Dictionary<String, Any>>, you need to add a key-value pair like this:

stringArrayCompleteData[arrIndexSection] = [arrSingleRow[0]: arrSingleRow[1]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.