1

我发现的最常见的错误之一是当我在这样的块中引用“self”时:

 ...
 [self someMethodWhichTakesBlock:^() {
       self.something = @"something";
 }];
 ...

我应该写的是更像这样的东西:

 ...
 __block MyObject *_self = self;
 [self someMethodWhichTakesBlock:^() {
       _self.something = @"something";
 }];
 ...

有没有办法通过某种静态代码分析来捕捉这些潜在的错误?

4

0 回答 0