I have a project that has a library subproject that gets imported. I have access to the source code of both the main project and the subproject.
The subproject uses Core Text. Because the subproject must be used on pre and post 3.2 applications, Core Text is weak linked and all of the Core Text related code is wrapped in the logic:
#if defined(__CORETEXT__) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
The thought of this line of code is that if CoreText is not linked in, the code is skipped. If the iPhone version is less than 3.2; CoreText is not linked in.
The reason for this goal is that the main project(s) (and there are several) do not all use Core Text and if the don't then without the 'defined(CORETEXT)`, they will not compile.
This seems to work fine and everything compiles without an error on projects that use Core Text. However on execution, the code is not found and a runtime error along the lines of "NSString does not respond to XXXX" (part of the code is a category on NSString
).
Has anyone run into this? Is my question, partially vague due it being client work, clear?
Ideally I want to set this up so that the subproject does not need to be altered when the main project uses Core Text and when it does not.
Note that __CORETEXT__
is defined in the header of the Core Text framework.
Update on the issue
I have tried the suggestions offered so far and they are ineffectual. Perhaps a little more code will help to outline the issue. I have a category with the following header:
@interface NSString (Internal)
- (NSString *)stringByUnescapingEntities;
- (NSString *)flattenHTML;
- (NSString *)flattenHTMLAndParseParagraphBreaks:(BOOL)parseBreaks;
- (NSString *)stringByEscapingForURL;
- (NSString *)stringByEscapingForJSON;
#if defined(__CORETEXT__) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
- (CFAttributedStringRef)attributedStringFromHTML;
- (CFAttributedStringRef)attributedStringFromHTMLWithBaseAttributes:(NSDictionary*)baseAttributes;
#endif
@end
Positive Test
All of the methods outside of the #if
block work perfectly. All of the methods inside of the #if
compile perfectly, no warnings.
Negative Test
If I change __CORETEXT__
to something like __THIS_IS_NOT_REAL__
I will get a compile error for the methods inside of the block. Therefore I know, at compile time at least, that the __CORETEXT__
flag is defined and fully functional.
Runtime issue
However, when I go to access one of the methods that are declared inside of the #if block, I get the following error at runtime:
-[NSCFString attributedStringFromHTMLWithBaseAttributes:]: unrecognized selector sent to instance 0x689c000
Instance 0x689c000
being a NSString
.
If I remove the __CORETEXT__
logic check then everything works so long as the master project is using Core Text. If the master project is not using Core Text then compile errors about missing linkers shows up.
Hopefully that clarifies the issue.
NOTE: All projects are using the -all_load
flag; as it was needed for TouchXML
already.
I have created a test project that demonstrates the issue.