Skip to content

Instantly share code, notes, and snippets.

@yannxou
Last active August 29, 2015 14:15
Show Gist options
  • Save yannxou/b4f90cd144eee87f827e to your computer and use it in GitHub Desktop.
Save yannxou/b4f90cd144eee87f827e to your computer and use it in GitHub Desktop.
Swift: Find if rect contains a point by overloading equatable operator
func == (lhs: CGPoint, rhs: CGRect) -> Bool {
return CGRectContainsPoint(rhs, lhs)
}
// Example
var p1 = CGPoint(x: 10, y: 10)
var p2 = CGPoint(x: 10, y: 200)
var rect = CGRect(x: 0, y: 0, width: 100, height: 100)
if (p1 == rect) {
println("yes")
} else {
println("no")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment