• 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
Adding an observer to an NSOperation crashes my app.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adding an observer to an NSOperation crashes my app.


  • Subject: Adding an observer to an NSOperation crashes my app.
  • From: G S <email@hidden>
  • Date: Fri, 13 Jan 2012 23:30:15 -0800

Hi all.  Working on an iPhone app and encountered a stumper.

I have various kinds of operations (derived from NSOperation) to do async
queries over the Internet. As is the norm, I determine when they're
finished by observing their isFinished property, and getting the results in
observeValueForKeyPath (which as you may know is called in a secondary
thread).  This works great all over my app.  Except...

When one particular type of operation finishes, I want to create a
follow-up type of operation using info from the first. But when I do so,
calling addObserver on the operation crashes my app with a bad access.
Since observeValueForKeyPath is called in a secondary thread, I tried
creating the follow-up operation and setting the observer on the main
thread. Didn't help. This is being done in observeValueForKeyPath:

*GetMessagesOperation* msgOp = [[GetMessagesOperation alloc]
> initWithUserID:_user.getID() sinceLast:true              includeSystem:true
> includeUser:false skipRows:0 maxCount:50 DBManager:_pDatabaseMgr];
> *



> *[msgOp addObserver:self forKeyPath:@"isFinished" options:0
> context:getMessageContext];
> *



> *[_operationQueue addOperation:msgOp];
> *



> *[msgOp release];*


The context is a void* to a string; I use the same syntax for many other
operations that work fine. Here's how the contexts are defined:

*static void* systemInfoContext = (void*)@"sys";
static void* validateUserContext = (void*)@"user";
static void* getMessageContext = (void*)@"msg";*

It crashes instantly on that addObserver call.  Anybody have a guess here?
Thanks!

Gavin
_______________________________________________

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: Adding an observer to an NSOperation crashes my app.
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: TBXML question
  • Next by Date: Re: Is slowing down bindings updates possible?
  • Previous by thread: Re: Child windows appear to move when entering full-screen mode / how to detect full-screen transition
  • Next by thread: Re: Adding an observer to an NSOperation crashes my app.
  • Index(es):
    • Date
    • Thread