Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if framework has been added during compile time - iOS
    text
    copied!<p>I'm currently working on a project that has a class referencing the Security.h framework. Since this is a reusable class, and might be used in multiple projects, I wish to add a compile time check to <strong>check whether the Security framework has been added to the project</strong> or not. What I mean by added to the project is whether it has been added in the <strong>Link Binary With Libraries</strong> build phases for the current target.</p> <p>Now, I know that questions with similar titles have been asked multiple times, and <a href="https://stackoverflow.com/questions/15642067/check-for-frameworks-existence-at-compile-time">this particular question</a> seemed to be super close to what I'm looking for, but I did not find an answer there either.</p> <p>I've been using:</p> <pre><code>#ifdef __SENTINEL_VALUE_ ..conditional code here.. #endif </code></pre> <p>code, but this <strong>only</strong> works if the framework header declares the sentinel value in the main header. Let me provide two examples to compare and contrast:</p> <p><code>SystemConfiguration.framework</code> has a framework header <code>SystemConfiguration.h</code> which includes all the sub headers, but also declares its own sentinel value, namely <code>_SYSTEMCONFIGURATION_H</code></p> <p>Thus, checking it using <code>#ifdef _SYSTEMCONFIGURATION_H</code> works perfectly. However, for <code>Security.framework</code>, the framework header, <code>Security.h</code> does not declare its own sentinel value. Each of its sub headers declare their own sentinel value, but since they are being imported in <code>Security.h</code>, the sentinel value gets <strong>defined</strong>. Therefore, even if <code>Security.framework</code> is not included in the project (not linked in the build phases), an <code>#ifndef</code> for one of its sub headers returns a false value, since the sentinel value is defined owing to its import in the <code>Security.h</code> file (not to mention that this approach of checking for a sub header of a framework header makes me feel a little sad).</p> <p>So, my question is: For a unique case like <code>Security.framework</code>, what would be the appropriate <strong>compile time</strong> check to check whether the framework has been added to the <strong>Link Binary With Libraries</strong> phase (if such a check exists).</p> <p>Additionally, I know of the <code>NSClassFromString()</code> method and the <code>NS_CLASS_AVAILABLE</code> macros, but I'm not looking for a run-time solution.</p> <p>Thanks in advance all!</p> <p>Cheers!</p>
 

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