• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to set a TextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to set a TextField


  • Subject: Re: How to set a TextField
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 14 Mar 2016 00:17:42 -0700
  • Feedback-id: 167118m:167118agrif8a:167118s6E6_B6sKS:SMTPCORP

On Mar 13, 2016, at 23:50 , Gerriet M. Denkmann <email@hidden> wrote:
>
> - (void)computeSomething
> {
> 	self.message1 = @“Start computing”;
> 	//	some seconds of computations
> 	self.message1 = @“Result = 42”;
> }

Assume, conceptually, that drawing only takes place asynchronously (that is to say, setting a new value on the string invokes setNeedsDisplay, that’s all), and it’s obvious why this isn’t going to work.

But the real issue is not that the text field won’t update, it’s that you’re blocking the main thread with computation. You should move the computation off the main thread — using dispatch_async to a default queue. At the end of the computation, go back to the main thread (dispatch_async again, specifying the main queue this time) and put the result in the text field.

This is, of course, going to introduce threading issues into your design. If the background thread keeps its results private (within the thread) until you switch back to the main thread, you can actually update any permanent data structures on the main thread, avoiding the need for locks or other synchronization techniques. However, you have to arrange for the main thread to avoid trying to use the results before the background computation is done, or to start any new computations, until the old ones are done, as far as such safety checks are necessary for your app.

(You can use NSOperationQueue instead of GCD, but I don’t see a lot of advantage in that. The consequences are the same.)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How to set a TextField
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >How to set a TextField (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: How to set a TextField
  • Next by Date: Re: How to set a TextField
  • Previous by thread: How to set a TextField
  • Next by thread: Re: How to set a TextField
  • Index(es):
    • Date
    • Thread