美文网首页
GameplayKit

GameplayKit

作者: 四毛哥掉落的鳞片 | 来源:发表于2016-06-28 16:13 被阅读0次

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

      本文链接:https://www.haomeiwen.com/subject/lkdtjttx.html