Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andyiapan

macrumors newbie
Original poster
Feb 28, 2010
29
0
if i got an id *object
object[size] may be 20000,
but i want to

NSArray *listContent = [[NSArray alloc] initWithObjects:
[Product productWithType:eek:bjects[i+1] name:eek:bjects]
........
,nil];

how can i alloc all the objects in a listContent, i can't find out this use a for loop, thx
 
Code:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"txt"];
	id *objects;
	int i=0;
		
		NSString *myText = [NSString stringWithContentsOfFile:filePath];  
		
  
			
			int stringLength = [myText length];
			NSRange range = NSMakeRange(0, stringLength);
			NSString *newStr = [myText stringByReplacingOccurrencesOfString:@"\n" withString:@"	" options:NSCaseInsensitiveSearch range:range];
			
			
			NSArray *listItems = [newStr componentsSeparatedByString:@"	"];
			
			
			NSUInteger count = [listItems count];
			
			objects = malloc(sizeof(id *) * count);
			
			[listItems getObjects:objects];

		NSArray *listContent = [[NSArray alloc] initWithObjects:
							[Product productWithType:objects[i+1]  name:objects[i]],nil];

if i want to initWithObjects:  
productWithType:objects[1]  name:objects[0]],
productWithType:objects[3]  name:objects[2]],
........,nil];
i need to input one by one,
but i got objects[20000], can i use i for loop or other methods to initWithObjects? ThX
 
First of all please use the CODE bbtag for the code.
The "id" tag is the pointer to the object. You don't need to create a id*, unless you want a pointer to a pointer.
Why exactly are you using this line?
Code:
 objects = malloc(sizeof(id *) * count);
You could just use a NSMutableArray and add Objects to it.
like so.
Code:
NSMutableArray *array = [NSMutableArray];
for (int i=0; i< 15; i++)
{
   [array addObject:[MyClass constructorWithString:@"String"]];
}
And to access objects in an array use the objectAtIndex method.
Like so.
Code:
Class *myObject = [array objectAtIndex:8];
or
Code:
id myObject = [array objectAtIndex:8];
They both do the same thing
 
any searching algorithm or access text file(database) example
that i can as reference in the above case? THX
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.