ios - 为什么要导入 .m 文件?
<p><p>我有一个源文件,实际上它是一个 Google API 库。</p>
<p>它在 <code>GTLCommon_Sources.m</code> 上有这个代码:</p>
<pre><code>#if defined(__has_feature) && __has_feature(objc_arc)
#error "This file needs to be compiled with ARC disabled."
#endif
#import "Objects/GTLBatchQuery.m"
#import "Objects/GTLBatchResult.m"
#import "Objects/GTLDateTime.m"
#import "Objects/GTLErrorObject.m"
#import "Objects/GTLObject.m"
#import "Objects/GTLQuery.m"
#import "Objects/GTLRuntimeCommon.m"
#import "Objects/GTLService.m"
#import "Objects/GTLUploadParameters.m"
#import "Utilities/GTLBase64.m"
#import "Utilities/GTLFramework.m"
#import "Utilities/GTLJSONParser.m"
#import "Utilities/GTLUtilities.m"
</code></pre>
<p>但是,尝试构建它,结果是 <code>GTLCommon_Sources</code> 和 <code>GTLJSONParser</code> 上的重复符号。我尝试将源文件更改为 <code>#import "Utilities/GTLJSONParser.h"</code> 而不是 <code>#import "Utilities/GTLJSONParser.m"</code> 并且重复符号错误消失了。</p>
<p>谁能告诉我为什么这个库会导入一个 .m 文件?在 AFAIK 中,我们总是导入 .h 文件。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这只是构建所有源文件的便捷方式,无需将所有源文件都包含在您的项目中。见 <a href="https://github.com/google/google-api-objectivec-client/wiki/BuildingTheLibrary#compiling-the-source-files-directly-into-a-mac-or-ios-application" rel="noreferrer noopener nofollow">the documentation</a> .</p>
<blockquote>
<p>Rather than link to the GTL framework, you can compile the GTL library
sources directly into your own project. To do this, find the library's
GTLCommon_Sources.m and GTLCommon_Networking.m files, and drag the
files into your project's window.</p>
<p>Then add the library's source folders to the Header Search Paths entry
of your project's build settings: Source, Source/Objects,
Source/Utilities, Deps/gtm-session-fetcher/Source,
Deps/gtm-oauth2/Source, Deps/gtm-oauth2/Source/Touch (or
Deps/gtm-oauth2/Source/Mac).</p>
</blockquote>
<p>为此,请<strong>不要</strong>将任何其他来源(<code>GTLBatchQuery.m</code> 等)添加到您的项目中。</p></p>
<p style="font-size: 20px;">关于ios - 为什么要导入 .m 文件?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37560704/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37560704/
</a>
</p>
页:
[1]