jeudi 21 juin 2018

swift - if statement and array

I want to match a string from the DicX to a an existing title (title of a table which changes according to the cell selection).

var DicX = ["xx",
                 "yy",
                 "zz",
                 "qq"]

let DicYY = [["11", "22", "33", "44"],
               ["1", "2", "3", "4"],
               ["m", "n", "k", "b"],
               ["bb", "kk", "mm", "nn"]]

the title I'm comparing with is like this:

title = detailX.insideTitle

so I want that when the title string equal to one of the DicX strings, to show the corresponding strings for it in DicYY each one of the 4 on a button.

but can't get the match correct, I tried to do like:

            var currentX = detailX.insideTitle
            if DicX = currentX["DicX"] {
            }

I get this message :

Cannot subscript a value of type 'String' with an index of type 'String'

how can I do the if statement? and how to get the corresponding from DicYY?

Aucun commentaire:

Enregistrer un commentaire