Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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