You might consider storing the information for the languages as a dictionary as you mentioned, then you can access the all the values or keys using the standard accessors provided. For example, if you have a dictionary called languages, then you could get the keys or values as an array using the following:
languages = [1:"English", 2:"Latin", 3:"Spanish", 4:"French"]
One issue you might have in this case is ordering, since dictionaries are unordered by nature. You can extract the language names using the above method, sort the resulting array and display the sorted contents in the picker. Then you will need to find the key for a given value (Swift does not have this method, but Objective-C does) using a for-in loop or maybe consider using the NSDictionary type instead of Swift's dictionary. If you think that you might expand the definition of language, such as including country of origin or number of characters, etc, then creating an object to represent the language would be the better way to proceed. Hope this helps.
On Wednesday, February 25, 2015 at 9:15:31 AM UTC-8, Heidi Anselstetter wrote:
I have a table "languages" where I have data like "objectId" and "name". This data I want to show in a PickerView.
Fine so far, I put the "name" into an array and show it.
But I want to save the selection back to another table "settings". And there I need to save only the "objectId" of the selected pickerview row into "language".
As far as I can see, the UIPickerView works with arrays, but I can not store the objectId and the name in an array?
I would need to use a dictionary, right?
But a dictionary has no numeric index, so get error messages on functions like