How to create an Array of Strings in Objective c for iphone

后端 未结 4 1007
深忆病人
深忆病人 2020-12-30 19:48

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

4条回答
  •  半阙折子戏
    2020-12-30 20:16

    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.

提交回复
热议问题