我有一个字典,每个值都是一个数组。我想看看输入的数组是否与任何值匹配

时间:2016-06-09 15:48:30

标签: arrays swift dictionary

我的代码:

   var chords_dict = [
        "Suspended 2" : [0, 2, 7, 99, 99, 99],
        "Major" : [0, 4, 7, 99, 99, 99],
        "Minor" : [0, 3, 7, 99, 99, 99],
        "Mix 3" : [0, 3, 4, 7, 99, 99],
        "Suspended 4" : [0, 5, 7, 99, 99, 99],
        "Add 4" : [0, 4, 5, 7, 99, 99],
        "Augmented 5" : [0, 4, 8, 99, 99, 99],
        "Diminished 5" : [0, 3, 6, 99, 99, 99],
        "Minor 6" : [0, 3, 7, 9, 99, 99],
        "Major 6" : [0, 4, 7, 9, 99, 99]
    }

//This function will take the integer notation and convert to notes relative to tonic
func get_chord(tonic: String, notes_list: Array <String>, int_1: Int, int_2: Int, int_3: Int = 99, int_4: Int = 99, int_5: Int = 99) -> (String, String){

    var tonic = 0
    var chord_notes = [tonic, int_1, int_2, int_3, int_4, int_5]

    let sorted_chord_notes = chord_notes.sort()
    let dict_values = Array(chords_dict.values)

    if contains(dict_values, sorted_chord_notes){
//Error message here: cannot invoke "contains" with an argument of list type '(Array) <[Int]>, [Int]'

    return ("Test", "test")
}


    return ("Placeholder1", "Placeholder2")

}

let (string, string2) = get_chord("C", notes_list: notes, int_1: 2, int_2: 4, int_3: 7)

我想将一个数组传递给一个函数,以查看它是否与该字典中的任何值匹配,但我一直收到此错误:

0 个答案:

没有答案