To search for an object in an array with a specific property value, you can use the array's
filter method. For example, the following code returns an array of
PersonEntity objects whose last name is "Smith":
let personEntity = self.personEntityList.filter{ $0.lastName == "Smith"}.first
When searching on a property that contains unique values (one that guarantees a single entity is found), you can use the
first property to return a single entity:
let personEntity = self.personEntityList.filter{ $0.SSN == "123-45-6789"}.first
All the best!
Kevin McNeish
Author of
Learn to Code in Swift:
https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11Check out our
Robot Tic-Tac-Toe app:
https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8