iOS App Development Book/Video Series

General Category => FAQs => Topic started by: kjmcneish on October 14, 2015, 10:52:44 AM

Title: How to find a specific object in an array in Swift
Post by: kjmcneish on October 14, 2015, 10:52:44 AM
To find a specific object in an array in Swift, you pass a predicate that uses Swift's identity operator. For example:

Code: [Select]
let memberEntity1 = member.createEntity()
let memberEntity2 = member.createEntity()
let members: Array<MemberEntity> = [memberEntity1, memberEntity2];
let index = members.indexOf({$0 === memberEntity2})

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=11 (https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11)
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8 (https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8)