iOS开发-警告收录及科学快速的消除方法

来源:互联网 发布:怎么运营好淘宝店铺 编辑:程序博客网 时间:2024/05/17 06:12

一、详细科学的消除警告

现在你维护的项目有多少警告?看着几百条警告觉得心里烦么?你真的觉得警告又不是错误可以完全不管么? 如果你也被这些问题困惑,可以和我一起进行下面的操作。其实大部分的警告都是很好改的,把自己整个项目的警告撸一遍应该也就耗费半小时的时间,一次麻烦带来之后的清净这样不好么?

1.没有使用

Unused variable 'replyURL'

2.这种明明都能运行还说我没有定义的警告,是因为你这个协议虽然定义了,但是你这个协议可能还遵守了XX协议,然后这个XX协议没有定义导致会报这种警告,所以遇到这种警告要往“父协议”找。 举个栗子,上面这行就是腾讯授权的库里面报的警告,

Cannot find protocol definition for 'TencentSessionDelegate'

此协议遵守了TencentApiInterfaceDelegate协议,在TencentOAuth.h类中#import “TencentApiInterface.h” 警告可破

@protocol TencentSessionDelegate<NSObject, TencentLoginDelegate, TencentApiInterfaceDelegate, TencentWebViewDelegate>

3.这个警告比较新,是xcode6.3开始 为了让OC也能有swift的?和!的功能,你在声明一个属性的时候加上 __nullable(?可以为空)与__nonnull(!不能为空) 如果放在@property里面的话不用写下划线

 Null passed to a callee that requires a non-null argument

或者用宏NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END 包住多个属性全部具备nonnull,然后仅对需要nullable的改下就行,有点类似于f-no-objc-arc那种先整体给个路线在单独改个别文件的思想。 此警告就是某属性说好的不能为空,你又在某地方写了XX = nil 所以冲突了。

@property (nonatomic, copy, nonnull) NSString * tickets;@property (nonatomic, copy) NSString * __nonnull tickets;

4.他说你的父类实现了setget方法,但是如果你什么都不写,就会系统自动生成出最一般的setget方法,请用@dynamic 来承认父类实现的这个getset方法。

Auto property synthesis will not synthesize property 'privateCacheDirectory'; it will be implemented by its superclass, use @dynamic to acknowledge intention

5.一般是storyboard报的警告,简而言之就是你有的页面没有和箭头所指的控制器连起来,导致最终改页面可能无法显示。

Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.

6.iOS8之后呢,不要再用push拖线了,统一用show,他会自己根据你是否有导航栏来判断走push还是走modal

Deprecated: Push segues are deprecated in iOS 8.0 and later

7.导航栏的item 不支持用plain ,那就用Bordered呗。

Unsupported Configuration: Plain Style unsupported in a Navigation Item 

8.几张图标还是启动图找不到自己的位置,可能是一次导入了全部尺寸图片,但是右边的设置只勾了iOS8的 那iOS7尺寸的图标就会报此警告。删掉,或者对照右边匹配。

The launch image set "LaunchImage" has 2 unassigned images. The app icon set "AppIcon" has 2 unassigned images.

9.方法废除,旧的方法sizeWithFontToSize在iOS7后就废除了取而代之是boundingRectWithSize方法

'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:

10.使用未声明的方法,一般出现在@selector() 括号里写了个不存在的方法或方法名写错了。

 Undeclared selector 'historyAction'

11.这个和上面类似就是直接把上面那个@SEL拿来用会报这个警告

PerformSelector may cause a leak because its selector is unknown

12.这个宏声明重复,删一个吧

 'strongify' macro redefined

13.方法废除,一般一起出现

 'UITextAttributeFont' is deprecated: first deprecated in iOS 7.0 - Use NSFontAttributeName 'UITextAttributeTextColor' is deprecated: first deprecated in iOS 7.0 - Use NSForegroundColorAttributeName 'UITextAttributeTextShadowColor' is deprecated: first deprecated in iOS 7.0 - Use NSShadowAttributeName with an NSShadow instance as the value

14.他说这代码永远也轮不到他执行,估计是有几行代码写在了return之后

 Code will never be executed

15.一般出现在xxx.delegate = self ,应该在上面遵守协议

 Assigning to 'id<SXTableViewDelegate>' from incompatible type 'SXTabViewController *const __strong'

16.这个警告一般会出现在NSStringWithFormat里面 前面%d %lu 什么的和后面填进去的参数不匹配就报了警告

 Format specifies type 'unsigned long' but the argument has type 'unsigned int' 

17.类似于上面,也是format里面前后写的不匹配

Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead

18.经典警告,遵守了协议,但是没有实现协议方法。 也可能你实现了只是又加了个参数或是你写的方法和协议方法名字有点轻微不同

Method 'dealWithURL:andTitle:andKeyword:' in protocol 'SXPostAdDelegate' not implemented

19.这个可以自动修正,就是说abs适用于整数绝对值,要是float取绝对值要用fabsf

Using integer absolute value function 'abs' when argument is of floating point type

20.有的方法你用的太落后了,也有的方法你用的太超前了。 说这个最大宽度在iOS8之前的系统是要坑的

 Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

21.你可以在otherlink 中加入 -Wl,-no_compact_unwind 去掉该警告,根据苹果的解释,这个是由于某些地方 c/c++/oc/oc++混用会造成编译警告。一般没有什么伤害。

 Too many personality routines for compact unwind to encode

22.说这个ssid必须要定义个这个属性的getter方法,如果警告是setSsid就是setter方法, 用@synthesize和@dynamic 都行,一个是让编译器生成getter和setter,一个是自己生成,如果你有模型分发或kvc之类的,选@dynamic就行

Property 'ssid' requires method 'ssid' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

23.未知的转义序列。 一般有个斜杠再加个东西他都会以为是转义字符,一看\)不认识就报警告了,一般正则表达式容易报这种警告

 Unknown escape sequence '\)'

24.这种可以点击自动修复,是典型的大小写写错了,他提醒了一下。

Property 'LoginPort' not found on object of type 'LoginLvsTestTask *'; did you mean to access property loginPort?

25.这是出现在switch语句中的警告, 一般可能是switch外面定义了个type但是并没有初始化(初始化操作都写在switch的各个分支里),然后在最后return type。 但是switch的有个分支没有对type初始化,他说如果你来到这个分支的话,那还没初始化就要被return。

Variable 'type' is used uninitialized whenever switch default is taken
0 0
原创粉丝点击