Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Created June 14, 2011 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjohndoe/1024839 to your computer and use it in GitHub Desktop.
Save johnjohndoe/1024839 to your computer and use it in GitHub Desktop.
Convert from NSRect to CGRect
// Convert from NSRect to CGRect.
NSRect baz = NSMakeRect(0, 0, 100, 100);
CGRect foo = *(CGRect*)&baz;
// Include this inline function in a header file.
NS_INLINE CGRect CGRectMakeFromNSRect(NSRect rect) {
return *(CGRect*)▭
}
// Doooooh! They already exist.. - I could not find 'em before.
CGRect rect2 = NSRectToCGRect(rect1);
NSRect rect1 = NSRectFromCGRect(rect2);
CGPoint point2 = NSPointToCGPoint(point1);
NSPoint point1 = NSPointFromCGPoint(point2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment