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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:10:31+00:00 2026-05-15T14:10:31+00:00

I have some iPhone SDK 4.0 code which initializes an NSOperationQueue and then adds

  • 0

I have some iPhone SDK 4.0 code which initializes an NSOperationQueue and then adds three classes (ClassA, ClassB, and ClassC) to run one after the other. ClassA, ClassB, and ClassC are all sub-classes of NSOperation.

The relevant code is included below.

ClassA *classA = [[ClassA alloc] init];
ClassB *classB = [[ClassB alloc] init];
ClassC *classC = [[ClassC alloc] init];

[classB addDependency:classA];
[classC addDependency:classB];

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[queue addOperation:classA];
[queue addOperation:classB];
[queue addOperation:classC];

[classA release];
[classB release];
[classC release];
[queue release];

The reason for the dependencies is because classB should only run if classA completes its operation successfully. Likewise, classC should only run if classB completes successfully.

At the moment I am having difficulty figuring out how to prevent, for example, classB from running if classA does not complete successfully. Continuing with this example, I was thinking of somehow evoking [NSOperationQueue cancelAllOperations] from within classA but I don’t know how to get a handle on the parent NSOperationQueue from within classA (which is an NSOperation sub-class). This was just my initial thought, so I would be open to any other better suggestions for achieving the same outcome!

There is conditional code within each of the classes to determine whether they have completed properly – at the moment they are just NSLogging “Success” or “Fail” to the Console for debugging purposes. In a perfect world I would just like to be able to replace the NSLog(@"Fail") statement in each class with some code which will stop all of the other classes in the NSOperationQueue from running.

Any suggestions would be most welcome (and appreciated).

  • 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-15T14:10:32+00:00Added an answer on May 15, 2026 at 2:10 pm

    You could set a property in classA :

    @property (readonly) BOOL completedSucessfully;
    

    and set this to YES at the end of classA’s main method.

    Then, just check it at the start of classB.

    - (void)main {
        if (NO == [[dependencies objectAtIndex:0] completedSucessfully])
            return;
    

    Now, classB will just stop if classA reports failure.

    NB You will probably need more error checking that in the example above i.e. making sure that you have dependencies, checking that it’s the correct class etc.

    - (void)main {
        for (id *temp in [self dependencies])
            if ([temp isKindOfClass:[ClassA class]])
                if (NO == [(ClassA *)temp finishedSucessfully])
                    return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems like a compatibility issue with IE. You could look… May 16, 2026 at 6:54 pm
  • Editorial Team
    Editorial Team added an answer in your dataset there is the ability to do filters,… May 16, 2026 at 6:54 pm
  • Editorial Team
    Editorial Team added an answer The simplest changes are generally to colour and background colour.… May 16, 2026 at 6:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I had a UIAlertView window which worked fine in iPhone OS 3.2.3, with SDK
I have some basic questions about core data (which I am new to) and
I have an iPhone app which submits user entered data to a SQL database.
Preface : I am new to the iPhone SDK, Obj-C, Interface Builder and Cocoa.
I'm developing for iphone-sdk 2.2.1 (so no CoreData cry ). So I'm using the
Disclaimer: I am an Xcode / iPhone SDK Noob. I am trying to establish
I've got the code below in my RootViewController (which is a UITableViewController). This code
I am having issues with UIButton with the iPhone SDK. I've determined that when
I have some text that needs to be displayed in my app. The text
I have an iPhone application where i'm showing a settings page using modal view

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.