xcode 我收到 AFNetworking 的编译器警告,但不应该。我如何解决它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13477109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I'm getting compiler warnings with AFNetworking, but shouldn't be. How do I fix it?
提问by ageektrapped
I'm using the most excellent AFNetworking
library in a project that I'm currently upgrading to iOS 6. I'm in the middle of the upgrade, whittling down the bunch of warnings that I get when compiling against the iOS 6 SDK.
我在AFNetworking
当前升级到 iOS 6 的项目中使用了最优秀的库。我正处于升级过程中,正在减少针对 iOS 6 SDK 进行编译时收到的一堆警告。
AFNetworking gives me two warnings in all targets:
AFNetworking 在所有目标中给了我两个警告:
SystemConfiguration framework not found in project, or not included in
precompiled header. Network reachability functionality will not be available.
and
和
MobileCoreServices framework not found in project, or not included in
precompiled header. Automatic MIME type detection when uploading files
in multipart requests will not be available.
Here's the thing, though: those two libraries
areadded in all my targets
. I'd like to get rid of those warnings the proper way; I won't modify the AFNetworking
files. I suspect it's Xcode being silly. It's admittedly a small thing, but leaving warnings around is bad practice.
不过,事情就是这样:这两个libraries
被添加到我所有的targets
. 我想以正确的方式摆脱这些警告;我不会修改AFNetworking
文件。我怀疑这是 Xcode 愚蠢。诚然,这是一件小事,但留下警告是不好的做法。
How can I remove those warnings?
我怎样才能删除这些警告?
I've tried restarting Xcode and cleaning. Both don't work.
我试过重新启动 Xcode 和清理。两者都不起作用。
回答by Keith Smiley
I'm not sure if you're using CocoaPodsor not but this is a known issue being tracked on the AFNetworking Github page.
我不确定您是否在使用CocoaPods,但这是 AFNetworking Github 页面上正在跟踪的已知问题。
I was able to fix this by adding the correct import statements directly to my `PROJECTNAME-Prefix.pch there I changed it to this.
我能够通过将正确的导入语句直接添加到我的 `PROJECTNAME-Prefix.pch 中来解决这个问题,我将其更改为这个。
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#endif
If you have something else in there don't delete it. Just add the imports for SystemConfiguration and MobileCoreServices.
如果你有其他东西,不要删除它。只需添加 SystemConfiguration 和 MobileCoreServices 的导入。
For OS X:
对于 OS X:
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <CoreServices/CoreServices.h>
#endif
回答by Mike Akers
If you're using swift: Xcode compiles Swift code before the Prefix.pch
file is compiled, so you'll get these warnings even if the correct imports are in your .pch file. The best solution I've found is to add them to the project's Bridging-Header.h
file before importing AFNetworking:
如果您使用的是 swift:Xcode 在编译Prefix.pch
文件之前编译 Swift 代码,因此即使正确的导入在您的 .pch 文件中,您也会收到这些警告。我发现的最佳解决方案是Bridging-Header.h
在导入 AFNetworking 之前将它们添加到项目文件中:
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "AFNetworking.h"
回答by TCB13
This has already been answered, but still, if you're developing a command line tool potentially to be compiled for both OS X and iOS (not App Store for sure), you can add this:
这已经得到了回答,但是,如果您正在开发一个可能为 OS X 和 iOS(肯定不是 App Store)编译的命令行工具,您可以添加以下内容:
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
#elif TARGET_OS_MAC
#import <CoreServices/CoreServices.h>
#endif
#endif
By evaluating the target you're compiling to, it will include the proper files.
通过评估您正在编译的目标,它将包含正确的文件。