Convert AWS amplify List to Array

I am using aws amplify and it returns all of its results into models and their type is something like List<ResourceSubCategory>. But I would like them in standard swift arrays so I can use all the functionality like .first and such. How can this be done easily?

My error: Cannot convert value of type 'List<ResourceSubCategory>?' to expected argument type '[ResourceSubCategory]'

Thank you!

  • How is List defined in amplify ? You should probably write a converter that explore all elements in List and append them in an Array.

Add a Comment

Replies

Suppose you are are capturing List<ResourceSubCategory> in variable list, You can create an array of ResourceSubCategory from list like this:

var array = \[ResourceSubCategory]()

for element in list { array.append(element) }

print(array) //here you get expected type