Skip to content

Instantly share code, notes, and snippets.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

AlexDenisov commented May 31, 2017

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
You can’t perform that action at this time.