I\'m trying to create an array of strings that can be randomized and limited to a certain x number of strings.
If the array could be randomized I could pick the firs
Do you want an array with nine strings in it?
[NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil]
Just a tip, it's not necessary to shuffle the contents of the array. Just randomize the access. For each card you want to pick from the deck, pick a random number and select the card at that index. Then, take the top card and place it where the card you just picked was.
If you really want to sort the array though, you can do it with very little code using -sortedArrayUsingSelector:
where your comparison method returns NSOrderedAscending
or NSOrderedDescending
randomly.
All C auto arrays like that will be full of garbage until you fill them. As long as it isn't getting filled with garbage later, everything is working as expected. However, Cocoa includes the NSArray class which is more common to use for arrays of objects (since it does proper memory management and works with the rest of the framework and all that).
As of Xcode 4.4, you can use Array Literals, which are much cleaner and easier to read. You no longer need to include 'nil'. For example:
NSArray *myArray = @[@"1", @"2", @"3", @"4", @"5"];