Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your app already has an event loop running, and it should already be idling in between user actions and while the network is being checked for new state. What you want to do is generate an event when the condition is triggered so the app can react. </p> <p>The simplest way to do this is to post a notification (within the app) when the condition occurs. Something like this:</p> <pre><code>// just guessing about your PlayerInfo here, and assuming ARC @property (nonatomic, strong) NSArray *cardsPlayed; @synthesize cardsPlayed = _cardsPlayed; // replace the synthesized setter with one that does the set and checks for // the condition you care about. if that condition holds, post a notification // - (void)setCardsPlayed:(NSArray *)cardsPlayed { _cardsPlayed = cardsPlayed; // is the condition about an array that's nil or empty? guessing 'either' here... if (!_cardsPlayed || !_cardsPlayed.count) { [[NSNotificationCenter defaultCenter] postNotificationName:@"CardsPlayedDidBecomeEmpty" object:self]; } } </code></pre> <p>Then, when initializing the object that cares about the condition (where you proposed that loop in your question)...</p> <pre><code> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cardsPlayedEmpty:) name:@"CardsPlayedDidBecomeEmpty" object:nil]; </code></pre> <p>This will cause cardsPlayedEmpty: to be invoked when the condition comes to pass. It should have a signature like this:</p> <pre><code>- (void)CardsPlayedDidBecomeEmpty:(NSNotification *)notification { } </code></pre> <p><strong>EDIT</strong> - I think your revised question is that you want to pause before checking server state,. You can do that using performSelector:withObject:afterDelay: ...</p> <pre><code>- (void)getRemoteState { NSURLRequest = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { // here, handle the response and check the condition you care about // post NSNotification as above here }]; } // now the code you're trying to write ... if ([PlayerInfo instance].playingMultiplayer == YES) { // give other players a chance to play, then check remote state // this will wait 20 seconds before checking [self performSelector:@selector(getRemoteState) withObject:nil afterDelay:20.0]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload