Re: MutableArrays losing its contents?
Re: MutableArrays losing its contents?
- Subject: Re: MutableArrays losing its contents?
- From: Lee Morgan <email@hidden>
- Date: Mon, 1 Dec 2003 12:43:37 -0500
On Dec 1, 2003, at 5:54 AM, email@hidden wrote:
Several options how I would produce such weird behavior:
a) You're somewhere overwriting the pointer to your array with a new
one to an empty array. The best indicator for this is if [yourArray
count] is 0.
This is I guess what is happening because when I NSLog then array's
contents this is what I get...
In the import method...
<CFArray 0x33e170 [0xa01900e0]>{type = mutable-small, count = 1, values
= (0 : <CFURL 0x3f6f30 [0xa01900e0]>{type = 0, string =
/Users/leemorgan/Movies/ Tech/G5 Intro.mov, base = (null)})}
When used later...
<CFArray 0x301650 [0xa01900e0]>{type = mutable-small, count = 0, values
= ()}
b) You're declaring the variable/outlet to hold the array, but you
forgot to initialize it. Often you get a crash, but sometimes you're
lucky. Also known to "straight C" programmers as `long* foo =
0xDEADBEEF;4
I init it within my initWithFrame method
c) You've declared your instance variable in the wrong scope, or
you've declared a variable of the same name as your instance variable
that "hides" it. That way, you get a new copy of the variable each
time.
I'm declaring and init my array in the class header and the
initWithFrame (respectfully).
The array's contents I declare and init in a if {} within the import
method and then add them the same time.
d) You're calling release or autorelease on your array element where
you shouldn't, thus undoing the "retain" the array itself did to
ensure things like this don't happen. A good indicator for this is
that [yourArray count] is still right, but the objects are all
garbage, or even cause access exceptions and bring down your program.
My array count is getting knocked back down to 0.
e) You got the order of calls wrong. openFile: on an NSDocument is
usually called *after* init, but *before* awakeFromNib. This comes in
handy for the cases where the file's contents decide what NIB you're
loading, but can be a real pain if you just wanted to update your
GUI. If any of your objects come from a NIB through an outlet, check
for this.
Not using NSDocument... I call
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil
types:fileTypes];
Within a Import File method that is simply linked to a menu item.
(I don't bother doing anything with the files until that method is
called.)
f) Your computer has gone nuts and you're not at fault. In that case,
the only thing that's helped me was to do a complete rewrite of the
entire project, or at least of the part that is misbehaving. ;-)
LOL. Knowing my luck its a mixture of this and another; just to and
some spice to my life. ;-)
Lee Morgan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.