2

I am trying to use the new shuffle method to shuffle my array: https://developer.apple.com/documentation/foundation/nsarray/1640855-shuffledarray?language=objc. But I just get an error saying: No visible @interface for 'NSArray' declares the selector 'shuffledArray'.

This is my code:

NSArray *shuffledArray = [array shuffledArray];

And my project is iOS 10.0+

Peter
  • 1,848
  • 4
  • 26
  • 44

2 Answers2

7

As you can see on the right column of the documentation, although this is a method on NSArray, it's located in the GameplayKit framework.

You need to import the framework :

#import <GameplayKit/GameplayKit.h>
deadbeef
  • 5,409
  • 2
  • 17
  • 47
  • 2
    Thank you! The error went away, but the app crashed when I tried to execute the code with this error: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI shuffledArray]: unrecognized selector sent to instance 0x1700ef200'" – Peter Jun 05 '17 at 22:42
  • @Peter Answer is to link binary, as shown here: https://stackoverflow.com/questions/47404093/calling-shuffledarray-method-crashes-app – Johnny Rockex Nov 10 '21 at 06:08
2

You should always use @import for this, as it offers some advantages over #import of frameworks. So on this case it would be: @import GameplayKit;