美文网首页
Xcode的静态分析(Analyze)的常见错误整理

Xcode的静态分析(Analyze)的常见错误整理

作者: 暗夜精灵_NightElf | 来源:发表于2017-11-29 10:56 被阅读0次

        大家可能有跟我一个类似的经历,写完了工程代码后或者刚入职接到了”前辈“的代码后,想看下这个工程里到底有没有内存泄露,就会不约而同了用起了Xcode的工具,Analyze,Leak分析一下。接下来会发现我用了静态分析后,给出了很多提示但是不知道如何解决,这篇专门为这些常见的提示信息给出一些分析。闲话不多说了==>进入正题:

    问题一:

    1.converting a pointer value of type 'NSNumber *' to a primitive boolean value;instead,either compare the pointer to nil or call -boolValue

    解答:

    很明显给出的提示是说NSNumber直接拿来布尔值来判断,可以将他转化后进行判断:

    问题二:

    2.nil passed to a Callee that requires a non-null 1st parameter

    解答:

    会有一个警告: nil passed to a callee that requires a non-null argument,意思是testpath形参不能传nil。

    根据上下意思,[LKDBUtils checkStringIsEmpty:]如果没值也是传出空字符串处理,改成如下即可:

    问题三

    3.value stored to 'bikeLat' is never read

    解答:

    提示比较清楚,该变量重来就被用过。删除掉就是了。

    问题四

    4.Value stored to 'numBikeStr' during its initialization is never read

    解答:

    初始化后没有用到,如果没用就不要声明 即可,或者没用到直接删除

    问题五

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

    解答:

    问题是说可变类型不应该是copy去修饰,代替方案用strong修饰词

    问题六

    6.Returning 'self' while it is not set to the result of '[(super or self) init....]'

    解答:

    写错了self==[super init] 改成 self = [super init]即可

    相关文章

      网友评论

          本文标题:Xcode的静态分析(Analyze)的常见错误整理

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