iOS底层

iOS开发之项目analyse问题总结

2022-04-08  本文已影响0人  我是卖报的小行家

1.nil passed to a callee that requires a non-null 3rd(1st 4th) parameter
2.nil assigned to a pointer which is expected to have non-null value
出现以上原因是参数不能为nil,可以在参数设置时候传入(nullable )
3.Value stored to 'result' is never read
result这个变量没有被使用,在当前类中搜索maxSize这个变量发现只是被赋值并没有被使用。解除这个提示:删除或者注视这行代码OK;
4.Call to 'dispatch_once' uses the instance variable '_onceToken' for the predicate value. Using such transient memory for the predicate is potentially dangerous
调用“dispatch_once”使用实例变量“_onceToken”作为谓词值。对谓词使用这样的临时内存有潜在的危险
5.Potential leak of an object stored into 'extendedImage'
YYImage里的一个错误,将其release就行

截屏2022-04-08 10.22.34.png
CFRelease(pngDatas[0]);

6.Called function pointer is null (null dereference) 被调用函数指针为空(空解引用)
7.Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
没有调用self = [super init];
8.Although the value stored to 'self' is used in the enclosing expression, the value is never actually read from 'self'

截屏2022-04-08 10.30.46.png

虽然存储到“self”的值在封闭表达式中使用,但实际上从未从“self”读取该值
修改:

{
    self = [super init];
    return self;
}

9.User-facing text should use localized string macro
面向用户的文本应该使用本地化的字符串宏
原因:
程序设置了多语言,程序里未使用NSLocalizedString
第三方库有多语言
解决办法:
字符串使用NSLocalizedString
忽略警告
可以在Build Settings里搜索 Missing Localizability 设置成NO

截屏2022-04-08 10.38.02.png
10.Value stored to 'waveWidth' during its initialization is never read
容易出现这个问题的情况:一个数据源却申请了两块内存。导致另外一个内存没用了。
例子1:想把两个可变数组分情况赋值
    //NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:0]; //错误
    NSMutableArray *tempArray; //正确:只需做一个可变数组tempMutArr的声明,不需要给它分配实际内存
    if (self.mSwitch.isOn) {
        tempArray = self.array1;
    }else{
        tempArray = self.array2;
    }
    
例子2:取值
    //NSMutableArray *datesArray = [[NSMutableArray alloc]init];//错误
    NSMutableArray *datesArray = nil;                           //正确
    datesArray = [_onDemandDictionary objectForKey:key];

    上述标明错误的语句的的错误原因是:
那样做会导致整段代码下来出现了一个数据源却申请了两块内存的情况。
从而导致静态检测内存泄露的时候,有内存泄漏的提示 
Value stored to 'tempMutArr' during its initialization is never read。
//form://https://www.jianshu.com/p/66c6f43d172a

11.nil returned from a method that is expected to return a non-null value
方法返回值加上nullable

上一篇 下一篇

猜你喜欢

热点阅读