Skip to content

Instantly share code, notes, and snippets.

@daehn
Last active February 14, 2017 14:31
Show Gist options
  • Select an option

  • Save daehn/50c83bd8832529e20c6d8523fe10ea2a to your computer and use it in GitHub Desktop.

Select an option

Save daehn/50c83bd8832529e20c6d8523fe10ea2a to your computer and use it in GitHub Desktop.
import Foundation
// Defining this breaks the behaviour of the existing '||' operator in some cases
public func ||(lhs: NSPredicate, rhs: NSPredicate) -> NSPredicate {
return NSCompoundPredicate(orPredicateWithSubpredicates: [lhs, rhs])
}
func foo() {
let cards = [String: [String]]()
let startingContactIndex: UInt = 3
// This still works
guard !cards.isEmpty || startingContactIndex > 0 else {
return
}
// But when the lhs is an expression…
// Binary operator '||' cannot be applied to two Bool operands
guard cards.count > 0 || startingContactIndex > 0 else {
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment