2

I have the following code which retrieves list of operating systems and list of their counts. I would like to get the count values and save them to an array:

let query = mdm.select(os,os.count)
                .filter(os != "")
                .group(os)

let results = try! db.prepare(query)

for items in results
{
    countArray.append(items[os])
    countOSArray.append(items[os.count]) // This does not work

}

I know how to get normal column results but how do you reference a column that returns a list of counts?

Martheli
  • 931
  • 1
  • 16
  • 35

1 Answers1

1

After some research the answer is as follows:

countOSArray.append("\(items[os.count])")

Since the count returns an int, the value must be converted to a string using the double quotes and \

Martheli
  • 931
  • 1
  • 16
  • 35