26

I've created a mutable array containing NSRect values. I want to check whether the NSPoint I created is within this rectangle. What is the best way to do this in cocoa.

4 Answers4

52

From the Foundation Functions Reference:

BOOL NSPointInRect (
   NSPoint aPoint,
   NSRect aRect
);

"Returns a Boolean value that indicates whether a given point is in a given rectangle."

aleclarson
  • 18,087
  • 14
  • 64
  • 91
DisplacedAussie
  • 4,578
  • 1
  • 27
  • 21
2

A valid question because not everyone realises that there are a great many helper functions provided in the Foundation NSRect Extensions Reference file which save you having to re-invent the wheel all over the place.

Have a quick read through the reference to see all the different places it can help. I found it very useful when starting out.

Abizern
  • 146,289
  • 39
  • 203
  • 257
1

NSPointInRect?

gargantuan
  • 8,888
  • 16
  • 67
  • 108
1

I started this thread What Cocoa/Core Foundation helper functions do you wish you knew about 2 years ago? You may find something else you didn't know about.

Community
  • 1
  • 1
Mark
  • 6,108
  • 3
  • 34
  • 49