Note that there are some explanatory texts on larger screens.

plurals
  1. POConfiguring conditional code in a subproject
    primarykey
    data
    text
    <p>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.</p> <p>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:</p> <pre><code>#if defined(__CORETEXT__) &amp;&amp; __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= __IPHONE_3_2 </code></pre> <p>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.</p> <p>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(<strong>CORETEXT</strong>)`, they will not compile.</p> <p>This <em>seems</em> 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 <code>NSString</code>).</p> <p>Has anyone run into this? Is my question, partially vague due it being client work, clear?</p> <p>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.</p> <p>Note that <code>__CORETEXT__</code> is defined in the header of the Core Text framework.</p> <h2>Update on the issue</h2> <p>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:</p> <pre><code>@interface NSString (Internal) - (NSString *)stringByUnescapingEntities; - (NSString *)flattenHTML; - (NSString *)flattenHTMLAndParseParagraphBreaks:(BOOL)parseBreaks; - (NSString *)stringByEscapingForURL; - (NSString *)stringByEscapingForJSON; #if defined(__CORETEXT__) &amp;&amp; __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= __IPHONE_3_2 - (CFAttributedStringRef)attributedStringFromHTML; - (CFAttributedStringRef)attributedStringFromHTMLWithBaseAttributes:(NSDictionary*)baseAttributes; #endif @end </code></pre> <h3>Positive Test</h3> <p>All of the methods outside of the <code>#if</code> block work perfectly. All of the methods inside of the <code>#if</code> <strong>compile</strong> perfectly, no warnings. </p> <h3>Negative Test</h3> <p>If I change <code>__CORETEXT__</code> to something like <code>__THIS_IS_NOT_REAL__</code> I will get a compile error for the methods inside of the block. Therefore I know, at compile time at least, that the <code>__CORETEXT__</code> flag is defined and fully functional.</p> <h3>Runtime issue</h3> <p>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:</p> <blockquote> <p>-[NSCFString attributedStringFromHTMLWithBaseAttributes:]: unrecognized selector sent to instance 0x689c000</p> </blockquote> <p>Instance <code>0x689c000</code> being a <code>NSString</code>.</p> <p>If I remove the <code>__CORETEXT__</code> 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.</p> <p>Hopefully that clarifies the issue.</p> <p><strong>NOTE:</strong> All projects are using the <code>-all_load</code> flag; as it was needed for <code>TouchXML</code> already.</p> <p>I have created a test project that demonstrates the issue.</p> <p><a href="http://zds.s3.amazonaws.com/CTTest.zip" rel="nofollow noreferrer">Test Project</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload