Wrapping CGRect in ObjC via @(rect) should be possible. __attribute__((objc_boxable)) is missing

Number:rdar://32486932 Date Originated:31-May-2017 05:52 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:10.3.2
Classification:Enhancement Reproducible:Always
A while ago Objective-C got literals and a shorthand for boxing. This works for integers, enums and for any struct that declares the __attribute__((objc_boxable)) - this was all built and there are even tests in Clang that test this. However the declarations in CoreGraphics have never been updated.

Steps to Reproduce:
Try to compile this: (or see sample code)

    CGRect rect = (CGRect){};
    NSValue *boxed1 = @(rect);
    NSLog(@"Value: %@", boxed1);

Expected Results:
Should compile.

Actual Results:
error: illegal type 'CGRect' (aka 'struct CGRect') used in a boxed expression
    NSValue *boxed1 = @(rect);
1 error generated.


This would probably take less than an hour to add everywhere. Doesn’t break any legacy code, makes syntax nicer for everyone. Fully backwards compatible. A total win!



Engineering has requested the following information regarding your bug report:

Please verify this issue with the macOS 10.13 beta and update your bug report at https://bugreport.apple.com/ with your results.

macOS 10.13 beta 3 (17A306f) https://developer.apple.com/download/

If the issue persists and it's applicable to your bug report, please attach a new sysdiagnose captured in the latest build and attach it to the bug report.

macOS sysdiagnose Instructions: https://developer.apple.com/services-account/download?path=/OS_X/OS_X_Logs/sysdiagnose_Logging_Instructions.pdf

Turns out, this is simple to add:

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;

Thanks https://gist.github.com/mayoff/08390f6d2f8a6d05b4a711cbeaf558a0 !

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!