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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:45:25+00:00 2026-06-16T02:45:25+00:00

I currently have some code that does something like this (massively simplified, but enough

  • 0

I currently have some code that does something like this (massively simplified, but enough to illustrate the point):

@property (weak) IBOutlet CustomViewClass *customView;

...

for (int i=0; i<iterations; i++) {

    // Crunch some data (Up to ~200,000 operations)...

    // Update view to represent where we are in the process:
    [_customView setNeedsDisplay:YES];

}

Whenever I run the code for a given number of iterations, the custom views drawRect: method is only called one time, once all of the iterations have completed.

What I would like is for the view to be forced to be updated after every iteration, and to wait until the view has been redrawn before going onto the next iteration – but I cannot find anywhere in the documentation how to get it working as I would like!

I feel like if I could simply call drawRect: directly that would solve my problem but I know NSView does not allow this!

Could anybody point me in the right direction?

  • 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-16T02:45:26+00:00Added an answer on June 16, 2026 at 2:45 am

    The lack of view updating isn’t even the biggest problem with your current approach. The biggest problem is that your application is hung until it finishes. The user cannot cancel (if you have even provided a Cancel button), tell the application to hide, do anything else in the application while the work proceeds, or quit the application.

    The correct approach is to move the body of the loop to an NSOperation. You can do this either by subclassing NSOperation or by creating one with a block. Then, throw all the operations into a queue.

    If what you’re doing in the loop can safely be run in parallel, then you should create a queue and use that one. If you need it to happen one operation at a time, use dependencies to chain each operation to the one before it. If it absolutely must happen on the main thread, you can use the main queue, but you should do the least amount on the main thread that you can safely get away with.

    As work proceeds, run some code on the main thread/main queue that tells your view to setNeedsDisplay:. Since the operations aren’t on the main queue (assuming you didn’t put them there), or at least are broken up, this can happen while work is ongoing.

    Further reading:

    • Managing Concurrency with NSOperation (a little old, as acknowledged at the top, but still a good introduction)
    • Concurrency Programming Guide
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that does something like this pseudocode: Use CURL to get
I have some code that currently uses a ST monad for evaluation. I like
I have some code that currently checks for minimum and maximum lentgh. I want
I have some python code that currently performs expensive computation by performing the computation
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I currently have some code which when you press the submit button, a marker
I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code
I have some code which I'm currently using to change the static-IP of a
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter
I am currently messing around with some code for an advertising network, i have

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.