When dealing with huge data, for example, photo data: Basic information such as id, filepath, date, filename, etc. Flags required for apps such as isSelected, rating, openEye, etc.
There is something like this, but it is often necessary to extract various sequences as needed.
Use Filter and Map.
ImageViewModel
struct ImageViewModel {
let id: String = ""
let name: String = ""
var isSelected: Bool = false
}
Get all the photos with isSelect set to true, When you want to put out the ids of those photos as a new array:
let imageViewModels = [ImageViewModel]()
let targetImageIds = imageViewModels.filter({ $0.isSelected }).map({ $0.id })
Recommended Posts