What is the best way to create and then search an array within an array made up of date from a CSV table?
So far I have:
Code:
NSArray *containerArray = [dataString componentsSeparatedByString:@"\n"]; //read in data from CSV file and separate it into 'row' strings
NSArray *rowTemp; //local variable just for my sake
NSMutableArray *tableArray;//mutable array to hold the row arrays
//For each index of containerArray:
//take the string object (string of CSV data) and then,
//create an array of strings to be added into the final tableArray
for (int i = 0; i < [containerArray count]; i++) {
rowTemp = [[containerArray objectAtIndex:i] componentsSeparatedByString:@","];
[tableArray addObject:rowTemp];
}
What is the best way to create and then search an array within an array made up of date from a CSV table?
So far I have:
Then when I try the following, it returns: (null)
any ideas? is there a better way?
Thanks in advance.
Use code tags, not quotes to include code.
In this code:
Code:
NSArray *containerArray = [dataString componentsSeparatedByString:@"\n"]; //read in data from CSV file and separate it into 'row' strings
NSArray *rowTemp; //local variable just for my sake
NSMutableArray *tableArray;//mutable array to hold the row arrays
//For each index of containerArray:
//take the string object (string of CSV data) and then,
//create an array of strings to be added into the final tableArray
for (int i = 0; i < [containerArray count]; i++) {
rowTemp = [[containerArray objectAtIndex:i] componentsSeparatedByString:@","];
[tableArray addObject:rowTemp];
}
You define a local variable tableArray, but then never create an array object. In non-ARC code, this should crash when you try to add an object to tableArray, since it will contain an invalid memory address.
In ARC, stack variables get set to nil for you, so the call to
[tableArray addObject:rowTemp];
Will simply not do anything, since tableArray will be nil.
You should change the declaration of your tableArray to read like this:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
You define a local variable tableArray, but then never create an array object. In non-ARC code, this should crash when you try to add an object to tableArray, since it will contain an invalid memory address.
In ARC, stack variables get set to nil for you, so the call to
[tableArray addObject:rowTemp];
Will simply not do anything, since tableArray will be nil.
You should change the declaration of your tableArray to read like this:
Thanks again for your prompt and helpful answer Duncan C. I saw a post by you from the summer saying that you did not like to use arrays of arrays for this type of application.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Well that would be much nicer, thanks for the explanation.
Am I to understand that alloc/init will be retained even when using ARC?
ARC hides most of that from you. What matters in ARC is the variable you assign it to. Local variables are strong by default, so they retain objects saved to them as long as they are in scope. When a local variable goes out of scope, the object it contained gets released.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
ARC hides most of that from you. What matters in ARC is the variable you assign it to. Local variables are strong by default, so they retain objects saved to them as long as they are in scope. When a local variable goes out of scope, the object it contained gets released.
Makes sense, thanks for the explanation.
The core functionality of my very first 'real' app is up and running thanks to your help, Duncan C.