Issue with split(or at least I think so)

I'm trying to make an app that'll suggest a color based on a keyword the user inputs. I store prediction from the model to a [String: Double] array and then compute the output color. However, I'm stuck on two strange errors. Here's my code:

extension Array where Element == [String: Double]{
	func average() -> RGBList{
		var returnValue = (r: 0, g: 0, b: 0)
		var r = 0
		var g = 0
		var b = 0
		for key in self{
			r = Int(key[0].split(",")[0]) * key[1]
			...
		}
		...
	}
}

The error is on the r = Int(key[0].split(",")[0]) * key[1] line

1. No exact matches in call to subscript
2. Reference to member 'split' cannot be resolved without a contextual type

You use:

r = Int(key[0].split(",")[0]) * key[1]

You could try breaking that line down into smaller components, to better understand why it doesn't work.

For example:

let x = key[0]

No exact matches in call to subscript

Oopsies!
It's much easier to debug smaller statements.

What you are calling "key" (bad name!) is actually a Dictionary<String, Double>

So if you said:

for dictionary in self {

That would iterate through the dictionaries in your array...
...then you could action the values in the dictionary:

for key in dictionary.keys {

What are you trying to do here:

		for key in self {
			r = Int(key[0].split(",")[0]) * key[1]
		}

self is an Array of dict [String: Double]

so key is [String: Double]

key[0] is incorrect.

If you want to access some key (note that dictionary are not ordered, so referring to item 0 is not a stable reference), you should get the array of keys

        let allKeys = [String] (self[0].keys)

and get some item

        allKeys[0] for instance

In the same way, key[1] is meaningless. What do you expect here ? The value ? Of which item ?

Please give an example of the array, and explain what you want to compute, that will help.

Issue with split(or at least I think so)
 
 
Q