I got an array of items and would like to know if there is an easier way to assign each property item.fullPath
to another array. Right now I am using a for in
loop.
var items: Array<String> = []
for item in storageListResult.items {
items.append(item.fullPath)
}
But is there something similar to this:
let items = storageListResult.items[].fullPath
You can do it using map
let items = storageListResult.items.map{$0.fullPath}
And in swift 5.2 you can also do it like
let items = storageListResult.items.map(\.fullPath)