Skip to content

Instantly share code, notes, and snippets.

@mayoff
Created May 31, 2017 15:43
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mayoff/08390f6d2f8a6d05b4a711cbeaf558a0 to your computer and use it in GitHub Desktop.
Save mayoff/08390f6d2f8a6d05b4a711cbeaf558a0 to your computer and use it in GitHub Desktop.
adding objc_boxable to CoreGraphics structs
@import Foundation;
@import CoreGraphics;
typedef struct __attribute__((objc_boxable)) CGPoint CGPoint;
typedef struct __attribute__((objc_boxable)) CGSize CGSize;
typedef struct __attribute__((objc_boxable)) CGRect CGRect;
typedef struct __attribute__((objc_boxable)) CGVector CGVector;
int main(int argc, const char * argv[]) {
@autoreleasepool {
CGRect rect = CGRectMake(0, 0, 100, 50);
NSValue *boxedRect = @(rect);
NSLog(@"boxed: %@", boxedRect);
}
return 0;
}
@steipete
Copy link

steipete commented May 31, 2017

This is the best thing ever. THANK YOU! Adding this to https://pspdfkit.com/blog/2017/even-swiftier-objective-c/

@AlexDenisov
Copy link

Here is a little story behind https://lowlevelbits.org/nsvalue-and-boxed-expressions/ 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment