'Converting a string to an array in Swift

How can I convert a string which is an array of arrays into an actual array of type [[String]]?

For example:

theString =  "[["Test1", "String"], ["Test2", "String"]]" 

then the converted array should be as below:

converted = [["Test1", "String"], ["Test2", "String"]]

Is there any way this can be done?

I cannot use theString.components(separatedBy: ", ") or Array(theString), I tried both of these and it does not give the expected result.

I am using Swift 5 on Xcode 13.2.1.

Any help is appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source