Edit AllPages

Foundation’s NSRect structure, defined in NSGeometry.h.

typedef struct { NSPoint origin; NSSize size; } NSRect;

The NSRect struct differs from QuickDraw’s Rect struct in two important ways:

NSGeometry.h defines a number of helper functions for working with NSRect structs. Some commonly used functions include:

NSStringFromRect is most handy when used in conjunction with NSLog for printing debug messages:

NSLog(@”frameRect = %@”, NSStringFromRect(frameRect));

Note that unlike Carbon API all of these API pass the entire structure on the stack. In Carbon, one typically passes the address of a Rect around. Don’t let that trip you up.

Foundation also defines the global variable:


Which is occasionally useful when performing set arithmetic with the aforementioned functions and the like.


I cleaned up the page a bit to incorporate the bit about “Carbon’s Rect” being incorrect or ambiguous. I also reworked the part that talked about how Rect was faster because it used ints, since integer math hasn’t been faster than floating point math for well over a decade.