xxxxxxxxxx
func addPhotoArray(_ photos: [Photo], addedPhoto: [Photo]) -> [Photo]{
var resultArray = photos
for photo in addedPhoto {
// Search for the object is it already exists
if let existingPhotoIndex = photos.firstIndex(where: { (tempPhoto) -> Bool in
return photo.id == tempPhoto.id
}) {
resultArray[existingPhotoIndex] = photo // Replace the object
}
else {
resultArray.append(photo) // Insert new Object
}
}
return resultArray
}