1

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 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

3

NSMutableArray is a growable array.

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

1 Comment

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.
0

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.