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 8857281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:33:08+00:00 2026-06-14T14:33:08+00:00

I am studing about NSOperation and I have a doubt about the correct way

  • 0

I am studing about NSOperation and I have a doubt about the correct way of implementing it for my situation.

In my app I want to perfom a lot of operations in background. Since my app can import data from a desktop software, my database can become very large depending of the situation. With this, reading and analysing data can take a few seconds and I don’t want my UI frozen during this time.

Lets supose that I have an class:

ClassX 
- (void) heavyOp1
- (void) heavyOp2
- (void) heavyOp3

Each heavyOp is related with ClassX, so it makes sense that they belong to the same class.

My questions and my options:

1) Should ClassX be a subclass of NSOperation?

I understood that operations should represent one task, but my class offers 3 different tasks. I could try to control the execution with some custom constructors, but I think that I am probably breaking a concept.

2) Using NSInvocationOperation is correct? I can’t cancel it!

I know that I can do something like that:

ClassX *myClassX = [[ClassX alloc] init];
NSInvocationOperation *myOp = [[NSInvocationOperation alloc] initWithTarget:myClassX selector:@selector(heavyOp1) object:nil];
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
[myQueue myOp];

but if I call [myQueue cancelAllOperations]; the ClassX will not respond to self.isCancelled because it don’t exist in NSInvocationOperation.

Forcing the class recognize with some code like this [myOp addObserver:myClassX forKeyPath:@"isCancelled" options:NSKeyValueObservingOptionNew context:nil]; works, but again I think that I am breaking concepts.

3) Create a subclass of NSOperation for each heavyOp method from my ClassX?

That would generate a lot of subclasses and can be hard to manage it, I don’t know if its correct.

So, what is the correct way to solve the problem? Anyone can give me advices? Maybe I am wrong with one of the options that I explained. If something is not clear, just ask and I will try to explain better.

  • 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-14T14:33:09+00:00Added an answer on June 14, 2026 at 2:33 pm

    I tend to think of NSInvocationOperation being used to retro-fit operations and queues to existing code. If I was starting from scratch, or even if I wanted more fine-grained control (the ability to cancel as you mention) I would definitely create subclass(es) of NSOperation.

    Without knowing exactly what your heavy operations are it’s hard to say with certainty, but I would also be inclined to create them as three separate classes. Cancelling each op may have different things that need to be done, so it’s clear to have the code to perform that cancellation in separate classes.

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

Sidebar

Related Questions

I have a little doubt about javascript, a new language that I'm studying... I
While studying about JMX, I have seen one of the important feature of it
I have recently started studying about threads. I thought of starting from the beginning
I have been studying as much as I can about the Module Pattern suggested
Studing STL I have written a a simple program to test functors and modifiers.
I was studying about browser performance when loading static files and this doubt has
I am studying for a final and have a few questions about RMI and
Im learning a lot about how MVC frameworks work by looking around and studying
I am new to HBase but I have setup and got some knowledge about
I've been studying .Net threading and have learned about the Threading.Task and Threading.Task.Parallel classes.

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.