已经第二次使用"坑爹"这个词了,但确实到了不能忍的地步.
EXC_BAD_ACESS
原因居然是, 对于成员变量的赋值要使用生成的getter方法而不是直接调用. 要用 self.value而不要直接使用value.
Objective-C的垃圾管理机制真是垃圾到不能忍.
As you know, the array method will create an autoreleased array, which you directly assign to your instance variable data.The problem is that the array will be destroyed as soon as the processing of the current event is completed.That’s because it’s added to an autorelease pool that will be drained at the end of the event loop. In order to ensure the array’s survival through event loops, you have a few alternatives. Here are three different lines of code you could use instead that would work:
data = [[NSMutableArray array] retain]; // survives draining of pool
-or-
data = [[NSMutableArray alloc] init]; // not autoreleased
-or-
self.data = [NSMutableArray array]; // uses the setter method