accessing data within a class
accessing data within a class
- Subject: accessing data within a class
- From: April Gendill <email@hidden>
- Date: Fri, 25 Jul 2003 12:47:02 -0700
I am so lost I don't know what to do....
let me try and explain and see if maybe you can help.
ok in my document controller I have a method that populates an array.
its an NSMutableArray and is declared in the header
interface Mydocument {
NSMutableArray *generatedNumbers;
<more stuff>
}
I have a function to generated random numbers and it begains
-(void)generateRandomNumbers:(id)sender{
int comparitor;
generatedNumbers=[[NSMutableArray alloc] init];
NSString *swapperString;
NSString *swapperOne;
NSString *swapperTwo;
<code to make a bunch of numbers>
<for loop that runs a specific number of times
and each itteration adds a number to the NSMutableArray generatedNumbers
by calling a method named "populate array"
it basically looks like:
[populateArray:generated];>
<after that it continues the loop>
after the loop it places the contents of the array into a TableView
item.
The generatedNumbers array I thought was declared protected so the
whole class could use it but in my save routine:
- (void)saveFile:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
NSArray *theArray =[self generatedNumbers];
//NSString *theData =[NSString stringWithFormat:@"%@",[myDocument
theSerial]];
NSString *theData =[NSString stringWithFormat:@"%@",[self
generatedNumbers]];
NSLog(@"the data is:%@",theData);
[panel setRequiredFileType:@"srgn"];
if ([panel runModal] == NSOKButton) {
//[[theData string] writeToFile:[panel filename]
[theData writeToFile:[panel filename]
atomically:YES];
}
}
the NSLog shows me that the generatedNumbers accessor method is
returning null.
and I do have an accessor:
-(NSMutableArray *)generatedNumbers{
NSLog(@"theSerial is returning: %@",generatedNumbers);
return generatedNumbers;
}
when the accessor prints to the console it is also null. Basically the
instant the generator method finishes and the information shows in the
tableview, the generatedNumbers array, which I thought was going to
stay populated, is purged and all the data is lost.
BUT when i write generatedNumbers to the console at the end of the
random number generator method where it is populated, I get the correct
data.
what am I missing... I know its something simple but I'm nearly in
tears since I have never once gotten an accessor method to return a
value other than nill or null in ANYTHING I have ever tried to write...
I'm really starting to hate cocoa, its feeling like its not worth
learning.
No here is the last part.... IF i place the save code at the end of the
for loop, it brings up a save window and writes the file in plain text
format perfectly.
Thank you.
a very frustraited April.
_______________________________________________
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.