Shuffling an array in objective-c [duplicate]
问题 Possible Duplicate: What’s the Best Way to Shuffle an NSMutableArray? I develop apps for iphone/iPad.I want to shuffle the objects stored in an NSArray.Is there any way to achieve it with objective-c? 回答1: Add a category to NSMutableArray, with code provided by Kristopher Johnson - // NSMutableArray_Shuffling.h #if TARGET_OS_IPHONE #import <UIKit/UIKit.h> #else #include <Cocoa/Cocoa.h> #endif // This category enhances NSMutableArray by providing // methods to randomly shuffle the elements.