swift - if statement and array

前端 未结 1 1633
孤城傲影
孤城傲影 2021-01-25 09:35

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\",
                      


        
相关标签:
1条回答
  • 2021-01-25 09:57

    This will do the job (if i got it right).

    import Foundation
    
    let DicX = ["xx",
                "yy",
                "zz",
                "qq"]
    
    let DicYY = [["11", "22", "33", "44"],
                 ["1", "2", "3", "4"],
                 ["m", "n", "k", "b"],
                 ["bb", "kk", "mm", "nn"]]
    
    let searchterm = "yy"
    
    for (index, elem) in DicX.enumerated()
    {
        if (searchterm != elem) { continue }
        print(DicYY[index]) // This will print ["1","2","3","4"]
    }
    
    0 讨论(0)
提交回复
热议问题