2021年5月2日星期日

Unable to append array to array

I know I'm doing something wrong but I do not know what..

All I would like to do here is add some pet to my Array<Pet>

What am I doing wrong here...

import UIKit    struct Person {      let id = UUID()      let name: String      var pets: [String]  }    final class City {      let people = [Person]()            func addPetFor(id: UUID, newPets: [String]) {          self.people.findPerson(by: id).pets.append(contentsOf: newPets)      }  }    extension Array where Element == Person {      func findPerson(by id: UUID) -> Person {          let foundPerson = self.first { person in              person.id == id          }          return foundPerson!      }  }  

Picture of failed attempt to append an array to an array

https://stackoverflow.com/questions/67362437/unable-to-append-array-to-array May 03, 2021 at 09:07AM

没有评论:

发表评论