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

  • Home
  • SEARCH
  • 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 8714189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:32:03+00:00 2026-06-13T05:32:03+00:00

I am currently using GCD. However, I’ve heard that NSOperation is actually a higher

  • 0

I am currently using GCD. However, I’ve heard that NSOperation is actually a higher level program. It’s far more complex though.

In GCD, do something at background is simply use this helper function I created:

+(void)doForeGround:(void (^)())block
{
    dispatch_async(dispatch_get_main_queue(), ^{
        block();
    });
}

+(void)doBackground:(void (^)())block
{

    //DISPATCH_QUEUE_PRIORITY_HIGH
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0), ^{
    //dispatch_async(dispatch_get_global_queue(-2,0), ^{
        block();
    });
}

-(void)doBackGround:(void (^)())block onComletion:(void (^)())onCompletion
{
    [BGHPTools doBackground:^{
        block();
        [BGHPTools doForeGround:^{
            onCompletion();
        }];
    }];
}

Will doing it with NSOperation be simpler?

Am I missing something? How would I do the same thing at NSoperation?

  • 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-06-13T05:32:04+00:00Added an answer on June 13, 2026 at 5:32 am

    You can do similar things with NSOperation as you’re doing with GCD. The main difference is that NSOperation provides additional functionality.

    For example:

    • NSOperation has a -cancel method. Dispatch queues have no concept of cancellation; all blocks enqueued on a queue will run to completion.
    • NSOperationQueue has a maximumConcurrentOperationCount property, which you can use (for example) to only allow 3 operations to run at a time. Dispatch queues have no such concept; they are either serial, allowing only 1 block at a time, or concurrent, allowing as many as libdispatch thinks advisable based on CPU usage and availability.
    • An NSOperation can have a dependency on other NSOperations, allowing you to defer execution of a particular operation until all of its dependencies have run. Other operations will be allowed to “jump ahead” in the queue while the dependent operation is waiting. Dispatch queues are always dequeued in strictly FIFO order. (You can somewhat imitate dependencies using the dispatch_group API, but that’s really targeted at a different kind of problem.)

    Now, if you’re not using any of those features, GCD works just fine. There’s nothing wrong with using GCD, per se. It’s just that NSOperation provides a convenient wrapper for some additional nice features.

    Here’s how you’d rewrite your examples above using NSOperationQueue:

    +(void)doForeground:(void (^)())block
    {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            NSLog(@"I'm running on the main thread!");
            block();
        }];
    }
    
    +(void)doBackground:(void (^)())block
    {
        // Note; rather than allocating a new NSOperationQueue every time, you could
        // allocate the queue once and just refer to that queue. For simplicity, I'll
        // skip that here.
        [[NSOperationQueue new] addOperationWithBlock:^{
            NSLog(@"I'm running asynchronously on whatever thread NSOperationQueue wants!");
            block();
        }];
    }
    
    -(void)doBackground:(void (^)())block onCompletion:(void (^)())onCompletion
    {
        [[NSOperationQueue new] addOperationWithBlock:^{
            block();
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                onCompletion();
            }];
        }];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using base64_encode for some $_GET params that i don't want regular user
Im currently using a script (that is working) where I can apply a certain
Im currently using a method that looks like the following code to add script
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither
Currently using MySQL version 5.1.6 This is my first real world build and so
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I currently using android NDK to write some native code in C. I have
I'm currently using the NEST ElasticSearch C# Library for interacting with ElasticSearch. My project
I'm currently using inline javascript to clear an input text's default value on focus.

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.