一.localizability issue=本地化錯(cuò)誤
User-facing text should use localized string macro錯(cuò)誤蝠猬,是由于項(xiàng)目配置了本地化统捶,解決辦法搜索localizability?如圖:
這個(gè)問題解決后榆芦,重新分析后,就不會(huì)有這個(gè)錯(cuò)誤了喘鸟,數(shù)量從999+變成了200.
二.Memory (Core Foundation/Objective-c/OSObject)=潛在的內(nèi)存泄漏
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...]'
報(bào)這種錯(cuò)誤如圖:
改為:
必須通過super來獲取self匆绣,再進(jìn)行操作
三.API Misuse(Apple)
1.Argument to 'NSMutableArray' method 'addObject:' cannot be nil
向可變數(shù)組增加一個(gè)可能是nil的對(duì)象
解決辦法:排除掉為nil的情況?
如圖:
改為
2.Key argument to 'setObject:forKey:' cannot be nil
設(shè)置的鍵可能為nil,
解決辦法:排除為nil的情況什黑。
3.Value?argument to 'setObject:forKey:' cannot be nil
設(shè)置的值可能為nil崎淳,
解決辦法:排除為nil的情況。
四.Logic error 邏輯錯(cuò)誤
1.Property of mutable type 'NSMutableArray' has 'copy' attribute; an immutable object will be stored instead
定義屬性時(shí)引用錯(cuò)誤愕把。NSMutableArray是可變數(shù)據(jù)類型拣凹,應(yīng)該用strong來修飾其對(duì)象
@property(nonatomic,copy)NSMutableArray *state;---錯(cuò)誤
@property(nonatomic,strong)NSMutableArray *state;---正確
2.Division by zero?
解決方法:運(yùn)行前判斷 如果除數(shù)為0森爽,則不要計(jì)算
例:_start = ++_start % _max?
改為:?if(_max!=0) {
? ? ? ? _start= ++_start%_max;
? ? }else{_start = 0;}
五.Dead store 沒用的對(duì)象
1.Value stored to 'XXX' is never read ?
解決辦法:注釋截圖04的代碼,咐鹤,city在后續(xù)并未使用拗秘,分配了內(nèi)存,卻一直未釋放
類似這種錯(cuò)誤祈惶,在代碼很常見雕旨,比如你做某個(gè)需求的時(shí)候需要這個(gè)對(duì)象,但是后續(xù)改動(dòng)后未使用捧请,那么這個(gè)對(duì)象就一直存在凡涩。
2.Value stored to 'array' during its initialization is never read
解決辦法如圖:
六.Memory error?
1.nil returned from a method that is expected to return a non-null value
類似這種錯(cuò)誤坦弟,排除掉nil的情況檐什。
尤其注意不要直接 return nil;?
如:
改為