I am selecting some simple data from parse.com in order to fill a PickerView with it.
I have an "objectId" and a "name". This data I want to populate int my PickerView.
First I loaded the data into an array, which works fine... The PickerView is displaying the data the right way.
But as I want to save the selection from the pickerView to parse, I need the objectId of the selected language item - in this case the objectId.
When I use a dictionary:
var languagePickerValues = [String : String]()
// within the query loop
self.languagePickerValues[object.objectId] = name
I get errors here:
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return languagePickerValues[row]
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int){
selectedLanguage.text = languagePickerValues[row]
self.view.endEditing(true)
}
as these functions try to access an array with an Int as numeric key which I don't have when working with dictionary.
For displaying purpose I could work with the array... To save the data to the API I need the objectId...
What would be the right thing to do?
what is object.objectId
? if its int or some other numeric type, then try:
self.languagePickerValues["\(object.objectId)"] = name
its because dictionary keys are strings, so just convert them with his:
"\(object.objectId)"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.