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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:03:22+00:00 2026-06-07T08:03:22+00:00

I had some code that created and added UIView subviews via a queue created

  • 0

I had some code that created and added UIView subviews via a queue created by [[NSOperationQueue alloc] init], and it led to strangely laggy behavior. Subviews were only added after abnormally long delays.

But then I switched to using [NSOperationQueue mainQueue] for these parts, and responsiveness turned normal.

I would just like an explanation for the laggy behavior I saw using the first approach.

  • 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-07T08:03:25+00:00Added an answer on June 7, 2026 at 8:03 am

    From Apple doc

    Threads and Your User Interface

    If your application has a graphical user interface, it is recommended that you receive
    user-related events and initiate interface updatesfrom your
    application’s main thread. This approach helps avoid synchronization
    issues associated with handling user events and drawing window
    content.
    Some frameworks,such as Cocoa, generally require this
    behavior, but even for those that do not, keeping this behavior on the
    main thread hasthe advantage of simplifying the logic for managing
    your user interface. There are a few notable exceptions where it is
    advantageous to perform graphical operations from other threads. For
    example, the QuickTime API includes a number of operationsthat can be
    performed from secondary threads, including opening movie files,
    rendering movie files, compressing movie files, and importing and
    exporting images. Similarly, in Carbon and Cocoa you can use secondary
    threads to create and process images and perform other image-related
    calculations. Using secondary threads for these operations can greatly
    increase performance. If you are not sure about a particular graphical
    operation though, plan on doing it from your main thread

    In addition, UI classes are not thread-safe according to the thread programming guide.

    So, avoid to update the UI from a thread different from the main thread.

    If you run an NSOperation (within a queue) you could update your UI (for example after having download some data required for your app lifecycle) performing a method in the main thread like the following:

    -(void)main {
    
        // e.g the delegate could be the controller that has the view that you want to update
        if (delegate) {
    
            NSURL *url = [delegate urlForDownloadOperation:self];
            if ( nil == url ) return;
            self.downloadedImage = [[NSImage alloc] initWithContentsOfURL:url];
            
            // e.g. rather than invoking processImage directly on the delegate, ensure that the method draw the image on the main thread
            [delegate performSelectorOnMainThread:@selector(processImage:) 
                withObject:self waitUntilDone:YES];
        }
    }
    

    Or you could send a notification to the component that need to update the UI like:

    - (void)main {
    
       NSURL *url = [delegate urlForDownloadOperation:self];
       if ( nil == url ) return;
       self.downloadedImage = [[NSImage alloc] initWithContentsOfURL:url];
       
       // e.g. send a notificatio to inform some components that it is ready to update the UI with some content
       [[NSNotificationCenter defaultCenter] postNotificationName:@"importData" object:self];
    }
    

    The component that needs to update the UI will register for that notification like

    - (void)processImage:(NSNotification*)notification
    {
        if (![NSThread isMainThread]) {
            [self performSelectorOnMainThread:@selector(processImage:) withObject:notification waitUntilDone:YES];
            return;
        }
    
        // update the UI here, you are running on the main thread
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had some code that constructed an object: function gridObjConst(id, itemName, itemPrice, itemListPrice, width,
I had some code that ran commands through Runtime.getRuntime.exec(String) , and it worked on
I had some decryption code (using wincrypt.h ) that lived within my FileReader.cpp class.
A co-worker asked about some code like this that originally had templates in it.
This question has two parts. Part 1. Yesterday I had some code which would
I had to convert some code (which deals with building a VBO of data
I had to de-compile some code and I don't know what this syntax is?
I'm writing some code here, and I'm having a had time. I have a
I'm having a problem with some code I've written. I've had to anonymize it,
Today I was tracking down a floating point exception in some code I had

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.