开发者

NSArray becoming invalid after assignment

开发者 https://www.devze.com 2023-03-10 07:37 出处:网络
Thi开发者_StackOverflow中文版s is a strange problem, but two of my NSArrays are becoming invalid right after assignment. I went into debug and verified this during assignment. The screenshot shows it

Thi开发者_StackOverflow中文版s is a strange problem, but two of my NSArrays are becoming invalid right after assignment. I went into debug and verified this during assignment. The screenshot shows it all. I must be missing a silly error somewhere - can someone please help!

Link to Screenshot

Thank You!


You need to send the -retain message to the array on assignment, like this:

ivar = [[NSArray arrayWithObjects:@"a", @"b", @"c", nil] retain];

The reason why they are going out of scope is because -arrayWithObjects: returns an autoreleased object. It is for this reason that you must send it the -retain message.

Also, don't forget to -release these objects in your -dealloc method.


Use -retain- dude. This will solve your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消