Extension for grouping array into two dimensional array based on element ([] -> [[]])
That looks like a clean implementation to me. One minor thing: I find it more
natural to assign the new index before the group array is extended,
so that you don't have to subtract one:

indexKeys[key] = grouped.count
grouped.append([element])


The Swift standard library defines many methods for the Sequence protocol and not
for concrete sequences like Array, examples are map, filter, min/max, contains ...

You can do the same with your method to make it more universally applicable:

extension Sequence {
    // ... no other changes necessary ...
}


However: You are essentially reinventing the wheel. In Swift 4 there is a
Dictionary(grouping:by)
method which does almost what your code does, only that a dictionary is returned:

let groupedThings = Dictionary(grouping: things, by: { $0.category } )
// [String : [Thing]]


The keys are the categories, and the values are arrays of corresponding things. With

Array(groupedThings.values)


you get a nested array which (apart from the order) is identical to what your method
returns.