2017-06-25 1 views
0

Je cette pickerData:Comment peupler UIPickeView du dictionnaire?

var pickerData: (id: String, value: [String: String])? 

quand je tape sur UITextField-je faire la prochaine:

@IBAction func whoCanSee(_ sender: UITextField) { 
    pickerData = (id: "viewOption", value: ["F": "Me and my friends", "M": "Only certain users", "E": "Every user"]) 

    sender.inputView = self.pickerView 
} 

et plus tard dans

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) 

Je suis en train de chercher des valeurs de value dans mon tuple comme:

self.pickerData!.value.values[row] 

mais il me renvoie cette erreur:

Cannot subscript a value of type 'LazyMapCollection<Dictionary<String, String>, String>' with an index of type 'Int' 

J'ai essayé aussi avec for...in mais dans ce clés évidemment je reçois toujours le premier élément, comme à chaque fois que ce bloc appelle encore et encore.

Comment puis-je résoudre mon problème?

Répondre

1

Vous utilisez un dictionnaire, donc vous ne pouvez pas lui donner un index.

let arr = Array(self.pickerData!.value) 
print(arr[row])