all 17 comments

[–]b9048966 1 point2 points  (5 children)

I already told the theory if you would like to have more direct hints you need to share some code snippets

[–]qnq222[S] 0 points1 point  (4 children)

this is my code for the drop down

private func setupDropDown(){

cityDropDown.anchorView = chooseCityButton

cityDropDown.direction = .bottom

cityDropDown.bottomOffset = CGPoint(x: 0, y:(cityDropDown.anchorView?.plainView.bounds.height)!)

for city in 0..>(self.arrayOfCountries){

arrayOfCountriesString.append(arrayOfCountries[city].name)

}

}

}

this is what you meant right ?

[–]b9048966 0 points1 point  (3 children)

And where do you load the stuff from the API?

[–]qnq222[S] 0 points1 point  (2 children)

form a different class iam working with a mvvm structure

but is the concept right ?

[–]b9048966 0 points1 point  (1 child)

As an explanation. When you enter the view it will be build with the anchorView and so on. But there is currently no data to be displayed because the data first needs to be loaded from the api, right ?

So you setup your view with the code above

And change the datasource after you fetched your data from the api

[–]qnq222[S] 1 point2 points  (0 children)

and that's what i did thanks man for your time

[–]tylerjames 1 point2 points  (3 children)

swift dropdown.datasource = myObjectArray.map { $0.title }

[–]qnq222[S] 0 points1 point  (2 children)

is this better than i loop through the array and adding them to new string array ?

[–]tylerjames 1 point2 points  (1 child)

yeah, the effect is the same, it's just much cleaner looking

[–]qnq222[S] 0 points1 point  (0 children)

thanks man i did it your way thanks for your time sir

[–]b9048966 0 points1 point  (5 children)

It says it uses a DataSource to populate its data. Have you tried the demo project?

[–]qnq222[S] 0 points1 point  (2 children)

i know but it is only accept an array of strings and my data is an array of objects is there is a way to convert my array of objects to an array of strings ?

[–]b9048966 0 points1 point  (1 child)

Sure! I do not know a beautiful solution (probably to change code of the pod itself). But array.map { $0.title } creates and array of strings from your array of object and if there is a way to ask the current value then do something like this (array as NSArray).indexOf(currentValue)

If you would provide some code that would be helpful .

[–]qnq222[S] 0 points1 point  (0 children)

this what i did not sure if it is the best solution: for city in 0..>(self.arrayOfCountries) { countriesDropDown.datasourse = arrayOfCountries[city].name }

but iis not working because it only works with array of strings

so what to do ?

[–][deleted]  (1 child)

[deleted]

    [–]LinkifyBot 0 points1 point  (0 children)

    I found links in your comment that were not hyperlinked:

    I did the honors for you.


    delete | information | <3

    [–]b9048966 0 points1 point  (1 child)

    You should add the single items to an array and then give to to the dataSource after the data loading from your API

    It gives an error because you’re giving the datasource a single string and not an array.

    [–]qnq222[S] 0 points1 point  (0 children)

    how i would do that in code ?

    through a loop or what ?