美文网首页
静态分析Analyze错误情况汇总

静态分析Analyze错误情况汇总

作者: 小白奔哥 | 来源:发表于2021-04-29 14:58 被阅读0次

    一.localizability issue=本地化错误

    User-facing text should use localized string macro错误,是由于项目配置了本地化,解决办法搜索localizability 如图:

    01

    这个问题解决后,重新分析后,就不会有这个错误了,数量从999+变成了200.

    二.Memory (Core Foundation/Objective-c/OSObject)=潜在的内存泄漏

    1.The 'didReceiveMemoryWarning' instance method in UIViewController subclass 'FlutterController' is missing a[super didReceiveMemoryWarning]call

    解决办法:在didReceiveMemoryWarning方法加上[super didReceiveMemoryWarning];

    同理的问题还有:

    [super viewDidDisappear:animated];

    [super viewWillAppear:animated];

    2.Instance variable used while 'self' is not set to the result of '[(super or self) init...]'

    报这种错误如图:

    09

    改为:

    10

    必须通过super来获取self,再进行操作

    三.API Misuse(Apple)

    1.Argument to 'NSMutableArray' method 'addObject:' cannot be nil

    向可变数组增加一个可能是nil的对象

    解决办法:排除掉为nil的情况 

    如图:

    02

    改为

    03

    2.Key argument to 'setObject:forKey:' cannot be nil

    设置的键可能为nil,

    解决办法:排除为nil的情况。

    3.Value argument to 'setObject:forKey:' cannot be nil

    设置的值可能为nil,

    解决办法:排除为nil的情况。

    四.Logic error 逻辑错误

    1.Property of mutable type 'NSMutableArray' has 'copy' attribute; an immutable object will be stored instead

    定义属性时引用错误。NSMutableArray是可变数据类型,应该用strong来修饰其对象

    @property(nonatomic,copy)NSMutableArray *state;---错误

    @property(nonatomic,strong)NSMutableArray *state;---正确

    2.Division by zero 

    解决方法:运行前判断 如果除数为0,则不要计算

    例:_start = ++_start % _max 

    改为: if(_max!=0) {

            _start= ++_start%_max;

        }else{_start = 0;}

    五.Dead store 没用的对象

    1.Value stored to 'XXX' is never read  

    04

    解决办法:注释截图04的代码,,city在后续并未使用,分配了内存,却一直未释放

    类似这种错误,在代码很常见,比如你做某个需求的时候需要这个对象,但是后续改动后未使用,那么这个对象就一直存在。

    2.Value stored to 'array' during its initialization is never read

    05

    解决办法如图:

    06

    六.Memory error 

    1.nil returned from a method that is expected to return a non-null value

    类似这种错误,排除掉nil的情况。

    尤其注意不要直接 return nil; 

    如:

    07

    改为

    08

    相关文章

      网友评论

          本文标题:静态分析Analyze错误情况汇总

          本文链接:https://www.haomeiwen.com/subject/dqlwrltx.html