views:

64

answers:

3

What is the best practice, even in general programming, when you have an undefined, possibly infinite, amount of items that you need in an array but don't have defined bounds. Can you define an endless array in objective c that you can keep pushing items onto, like other lanaguages have a list item.

Thanks for any help.

+3  A: 

NSMutableArray is a growable array.

http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSMutableArray_Class/Reference/Reference.html

Bo Williams
It's not infinite, though. All collection classes are bounded by your application's memory space, which means they can hold less than 4 GB worth of objects on 32-bit.
Chuck
A: 

The various Cocoa collection classes are your friends, especially NSMutableArray in this case. If you want infinite items, though, you may find you run out of time and space...

walkytalky
+1  A: 

Well, your question refers to Objective-C, but if you are using the Cocoa frameworks, there is the NSMutableArray class

Use as so: [NSMutableArray array]; [array addObject:anObject];

Check out its docs Here: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html

Tom H