自己项目的警告
比如我们定义一个designated initializer,参数都是nonnull
- (instancetype)initWithGivenName:(NSString *)givenName familyName:(NSString *)familyName NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithGivenName:(NSString *)givenName familyName:(NSString *)familyName
{
NSAssert(givenName && familyName, @"givenName and familyName must not be nil");
if (self = [super init]) {
self.givenName = givenName;
self.familyName = familyName;
}
return self;
}
当实现父类的designated initializer时,调用上面这个方法并且传入参数为nil。显然,编译器对此产生警告
- (instancetype)init
{
return [self initWithGivenName:nil familyName:nil];
}
![](http://upload-images.jianshu.io/upload_images/1798073-67385ecd68b1c46e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
FE0ABDC9-1B8A-46E1-B830-4DB49726380F.png
- 找到警告类型
右击警告,选择在日志中显示
![](http://upload-images.jianshu.io/upload_images/1798073-5c42eb15ffddcc82.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
63568C18-C326-414F-96A5-DA1A80792933.png
-W
+警告类型 : 意味着打开某种类型的警告,-Wnonnull
打开nonnull类型的警告
-Wno-
+警告类型 : 意味着关闭某种类型的警告,-Wno-nonnull
关闭nonnull类型的警告
![](http://upload-images.jianshu.io/upload_images/1798073-9729d71ee017669a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
69960C85-AA3C-4DA7-B1CA-BAD90A4A7963.png
- 忽略某些行警告,被宏包裹的行忽略指定警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
- (instancetype)init
{
return [self initWithGivenName:nil familyName:nil];
}
#pragma clang diagnostic pop
值得注意的是 : 这里是-Wnonnull
- 禁用某个文件警告
![](http://upload-images.jianshu.io/upload_images/1798073-dfca514ea861cbdf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
08DCEE87-30B4-4842-BF29-E15FAF28B564.png
- 禁用某个target警告
![](http://upload-images.jianshu.io/upload_images/1798073-fc08c180925a638d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4B118D04-8E44-4DB7-89BB-28B122A5815F.png
第三方库的警告
当我们使用CocoaPods管理库依赖时,可以通过Podfile语法禁止第三方库的警告
CocoaPods管理AFNetworking和SDWebImage
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'CocoaPodsDemoWithOC' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for CocoaPodsDemoWithOC
pod 'AFNetworking', '2.5.0'
pod 'SDWebImage', '3.7.5'
end
- 禁止所有来自CocoaPods的警告
inhibit_all_warnings!
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
inhibit_all_warnings!
target 'CocoaPodsDemoWithOC' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for CocoaPodsDemoWithOC
pod 'AFNetworking', '2.5.0'
pod 'SDWebImage', '3.7.5'
end
- 禁止指定Pod的警告
这里禁止AFNetworking的警告
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'CocoaPodsDemoWithOC' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for CocoaPodsDemoWithOC
pod 'AFNetworking', '2.5.0', :inhibit_warnings => true
pod 'SDWebImage', '3.7.5'
end
- 禁止除了指定Pod之外的警告
这里禁止SDWebImage的警告
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
inhibit_all_warnings!
target 'CocoaPodsDemoWithOC' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for CocoaPodsDemoWithOC
pod 'AFNetworking', '2.5.0', :inhibit_warnings => false
pod 'SDWebImage', '3.7.5'
end