Need objective-c pause / wait function

I need to add the Pause / Wait function to the iPhone objective-c app. The sleep () function does not work for me.

You need to add a pause / standby function between them.

myscore += [self getcard];

myscore += [self getcard];
+3
source share
4 answers

I did not see such a function for objective-c, but I used NSTimer, which calls a specific function in the time interval of your choice.

http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSTimer_Class/Reference/NSTimer.html

, scheduleTimerWithTimeInterval: target: selector: userInfo: repeat: . "" , - , , , .

scheduledTimerWithTimeInterval:1          // Ticks once per second
                        target:myObject   // Contains the function you want to call
                      selector:@selector(myFunction:) 
                      userInfo:nil
                       repeats:YES
+3

[NSRunLoop currentRunLoop] 2 , , :

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
+3

, , performSelector: withObject: afterDelay: .

: 5 :

[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:5.0];
+1

dispatch_after GCD ( )

myscore += [self getcard];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    myscore += [self get card];
});
0

Source: https://habr.com/ru/post/1754898/


All Articles