Previously, using Objective-C, I could use performSelector: to repeat the action after a random period of time, which can vary from 1-3 seconds. But since I cannot use performSelector: in Swift, I tried to use "NSTimer.scheduledTimerWithTimeInterval". And he works to repeat the action. But there's a problem. Set a temporary variable to call a function that will generate a random number. But it seems that NSTimer uses the same number every time it repeats the action.
This means that the action is not performed randomly, but instead, after a certain period of time, which is randomly generated at the beginning of the game and used throughout the game.
Question: is there a way to set NSTimer to create a random number every time it performs an action? Or should I use a different method? Thank!
source
share