Sweeper Sweeper - 7 months ago 8
Swift Question

What is the name of this type?

In my app, I used a very complicated data structure:

[(category: String, items: [(String, String)])]


I know that:


  • [Int]
    is "an array of
    Int
    "

  • (String, String)
    is "a tuple of
    String
    and
    String
    "



So what should I call the above type?

Maybe


An array of tuples of
String
and an array of tuples of
String
and
String



?

But that sounds like three types:

[(String)] and [(String)] and String


which is a little confusing.

How should I call this type?

Answer

Don't over-use tuples. Create a type for the outer tuple:

struct MyStruct {
    var category : String
    var items : [(String, String)]
}

Now it's much easier to say what this is: it's an array of MyStruct.