I'm using NSArray
's indexesOfObjects(passingTest:), but after I converted my code to Swift 3 I get the error: "Ambiguous use of 'indexOfObject(passingTest:)'".
My code below worked fine with Swift 2.3.
let indexesOfBubbleConstraints = bubbleConstraints.indexesOfObjects(passingTest: { (constraint, idx, stop) in
if let view = constraint.firstItem as? UIView{
return view.tag == usernameTag
}
else{
return false
}
})
For Swift 3, I also had to cast constraint
to AnyObject
, but that doesn't fix the actual problem.
I ended up using func indexesOfObjects(options: NSEnumerationOptions = [], passingTest: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool)
with an empty Array for options as below. This works, but I still don't understand why I'm getting the "Ambiguous..." error with my original implementation.
let indexesOfBubbleConstraints = bubbleConstraints.indexesOfObjects(options: [], passingTest: { (constraint, idx, stop) in
if let view = (constraint as AnyObject).firstItem as? UIView{
return view.tag == usernameTag
}
else{
return false
}
})