No way to weakly reference string constants introduced after OS X major release

Originator:jurewitz
Number:rdar://12772011 Date Originated:
Status:Open Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:Always
 
The Illustrious Greg Parker asked that I file the following bug:

AppKit introduced a few string constants in 10.7.3 that we need to weakly reference. Unfortunately, our minimum deployment target is also 10.7, so we don't get these automatically weak-linked for us automatically by Xcode:

APPKIT_EXTERN NSString * const NSWindowDidChangeBackingPropertiesNotification NS_AVAILABLE_MAC(10_7); // added in 10.7.3; userInfo keys: NSBackingPropertyOldScaleFactorKey, NSBackingPropertyOldColorSpaceKey

APPKIT_EXTERN NSString * const NSBackingPropertyOldScaleFactorKey NS_AVAILABLE_MAC(10_7); // added in 10.7.3; an NSNumber
APPKIT_EXTERN NSString * const NSBackingPropertyOldColorSpaceKey NS_AVAILABLE_MAC(10_7);  // added in 10.7.3; an NSColorSpace

when running on 10.7.2 and below we hit the following crash:

OS Version:      Mac OS X 10.7.2 (11C74)

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000

Application Specific Information:
dyld: launch, loading dependent libraries


There is apparently no way to work around this problem other than modifying the system headers, which is a mega bummer.

It would be great if these headers were corrected to not require this.

Comments

Workaround

One suggested workaround:

You can manually force weak-import of those symbols by re-declaring them:

#import <AppKit/AppKit.h> __attribute__((weak_import)) extern NSString * const NSBackingPropertyOldScaleFactorKey;

Don't forget to remove the redeclaration when your deployment target improves in the future.


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!