Xcode 12 fails to interpret traitCollection with Interface builder

Originator:tobias.kress
Number:rdar://FB8799442 Date Originated:14-Oct-2020 11:44 AM
Status:Duplicate/23549463 Resolved:
Product:Xcode Product Version:Version 12.0.1 (12A7300)
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
Summary:
This is a duplicate of radar #23549463

When using IBDesignable properties, as a workaround for not having sizing class support, a common approach is to use traitCollection with IBDesignable variables one per sizing class. However Xcode doesn’t interpret traitCollection and always uses any / any when showing interface builder.. This works as expected in the similar and device, however in interface builder only any / any is used.

Steps to Reproduce:
Setup IBInspectable variables for each sizing class :-
@property (nonatomic) IBInspectable CGFloat AaShadowHeight;
@property (nonatomic) IBInspectable CGFloat RrShadowHeight;
@property (nonatomic) IBInspectable CGFloat CcShadowHeight;
@property (nonatomic) IBInspectable CGFloat RcShadowHeight;

Use those variables in your drawRect method.
Set a different value for each property.

Use self.traitCollection in your drawRect method :-

- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    CGFloat l_shadHeight = self.AaShadHeight; // 24.1
    
    if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact)
    {
        if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
        {
            //iphone3.5 / 4 / 4.7 landscape
            l_shadHeight = self.CcShadHeight;
        }
    }
    
    if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular)
    {
        if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular)
        {
            //ipad landscape
            l_shadHeight = self.RrShadHeight;
        }
        if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact)
        {
            //iphone6+
            l_shadHeight = self.RcShadHeight;
        }
    }

Build your framework file (contains drawing class).
Open your storyboard.
Change your sizing class to regular / regular.
Change the IBDesignable value for regular / regular - see no change.
Change the IBDesignable value for any / any see the change.

Expected Results:
To have traitCollection work with the interface builder when using IBDesignable properties for each sizing class.

Actual Results:
Any / any IBDesignable property is used in all cases

Regression:
Always

Notes:
None

Comments


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!