NSArray becoming invalid after assignment
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.
精彩评论