I had a similar problem. I was trying to move a spaceship along the x axis. I basically generated a random number and ran an action with that. Then within the completion block I recursively called the method again to repeat the process:
- (void)autopilot {
if (!self.dead) {
CGVector delta = CGVectorMake((arc4random() % 125), 0);
NSInteger multiplier = arc4random_uniform(2);
multiplier = multiplier == 0 ? -1 : 1;
delta.dx *= multiplier;
CGPoint position = self.position;
position.x = position.x <= 0.0 ? 0.0 : position.x;
position.x = position.x >= self.size.width ? self.size.width : position.x;
SKAction *move = [SKAction moveBy:delta duration:0.4];
[self runAction:move completion:^{
[self autopilot];
[self shoot];
}];
}
}