Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:13:16+00:00 2026-05-25T00:13:16+00:00

I have an app that when the main home screen is loaded I check

  • 0

I have an app that when the main home screen is loaded I check for sync updates in the background. If there is a slow connection or a user who moves through the app fast a bunch of these requests could stack up in the background. To prevent this I want to implement a BOOL variable that I toggle YES or NO to prevent multiple requests from going out to check for sync.

So my code would be something like this when a request is started:

 NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
 NSString *key = [NSString stringWithFormat:kVarAllowSyncRequest, aManufacturerID];
 [d setBool:NO forKey:key];

I know this will work but this will be called 100’s of times during my app’s use – is that something I even need to worry about?

Is there a better approach to doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:13:17+00:00Added an answer on May 25, 2026 at 12:13 am

    User Defaults is a good place to put preferences and information that doesn’t change or need to be accessed more than two or three times per session. Accessing the defaults means hitting the disk, which is slow; you don’t want to use it for something like checking a flag many times a minute.

    The application delegate is a handy place to store information that genuinely needs to be accessible to many objects in your application, since it is always accessible via [[UIApplication sharedApplication] delegate], but you should think carefully about your app design before weighing that object down with lots of ivars just because it seems convenient.

    Presumably there is only one object, possibly a view controller, which is responsible for sending out these requests. That is the place to put the flag. From your description, it doesn’t sound like you need an app-global variable at all. The flag is only used by the object which initiates the request, and so it is the only object which needs to know about it. The flag can be an ivar.

    If, in fact, you have a class, which may have many instances each of which will send out a request, then the correct solution would be to have a class-level flag that any instance has access to. This is straightforward. In your implementation file, declare a variable to hold the flag:

    // RequestMaker.m
    
    #import "RequestMaker.h"
    
    static BOOL allowSyncRequest = YES;
    
    @implementation RequestMaker
    // etc.
    

    It is declared static to make it only visible in this “compilation unit” (loosely, in this file).

    Then you create a class method each to set and get this flag:

    + (BOOL) allowSyncRequest {
        return allowSyncRequest;
    }
    
    + (void) setAllowSyncRequest: (BOOL)b {
        allowSyncRequest = b;
    }
    

    Now, each time one of your RequestMaker instances wants to start a request, it should check the flag; if it’s YES, then you can turn the flag off and start a request. You will also need to make sure to reset the flag when the request finishes.

    (This all assumes that you are not explicitly working on different threads for your requests. If you are, then you should look into GCD queues and maybe semaphores. There’s an excellent set of writeups by Mike Ash that make fun reading even if you don’t want to use GCD.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a mvvm app that the main window is a tab control. i
I have an app that opens a non-modal form from the main form. The
I have an app that so far consists of two Activities: The Main Menu
I have module application. When I run it, the main window of that app
The main idea is that I have several worker instances of a Rails app,
I have a widget that supposed to call an Activity of the main app
My app has a main login/password screen where user enters credentials and submits the
I have a media player that stops playing whenever the user closes the app,
In my app I have couple activities. How to setup that every time user
In my Android app, I have a main activity that serves as an entry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.