静态代码分析,以找到块内“自我”的引用?

时间:2013-02-12 15:01:37

标签: objective-c objective-c-blocks code-analysis

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

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

我应该写的更像是这样:

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

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

0 个答案:

没有答案