GameplayKit

1. It can shuffle an array. Like in the FlagGame, we want to show up 3 different country flags, one way is to shuffle the array and the pick the first 3.

2. It has a special method called nextIntWithUpperBound(), which lets you specify a number as your "upper bound" – i.e., the cap for the numbers to generate. GameplayKit will then return a number between 0 and one less than your upper bound, so if you want a number that could be 0, 1 or 2 you specify an upper bound of 3.

to generate a random number between 0 and 2 inclusive:

var correctAnswer = 0

correctAnswer = GKRandomSource.sharedRandom().nextIntWithUpperBound(3)

你可能感兴趣的:(GameplayKit)