NSThread selector trouble

Discussion in 'iOS Programming' started by patrickq007, Aug 24, 2009.

  1. patrickq007 macrumors newbie

    Joined:
    Aug 24, 2009
    #1
    Here is a code segment I wrote:

    Code:
    MyProcessorClass *myInstance = [[MyProcessorClass alloc] init];
    // Set some instance variables of myInstance
    myInstance.myDelegate = self; // current object implements a delegate
    
    // Start the thread to do the processing...
    // "info" is a NSDictionary
    [NSThread detachNewThreadSelector: @selector(MyProcessorClass::doTheWork toTarget:myInstance withObject:info];
    The application seems to crash the instant I make that call, even though all parameters check out before the call. Any ideas? Something fishy in the selector syntax (most example use a selector to a method in the current class, here I use a selector in a different class)?

    Thanks!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Where is doTheWork defined? If it's an instance method on MyProcessorClass, then the selector would be @selector(doTheWork). If doTheWork takes an argument, then it should be @selector(doTheWork:).
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    What is this? This is not C++. We don't use ::. A selector is not specified for a specific class.
     
  4. patrickq007 thread starter macrumors newbie

    Joined:
    Aug 24, 2009
    #4
    Quite right, thanks! I am new to obj-c and to me at least, what got me confused is the fact that doTheWork: appeared unresolved without specifying its class. I guess that selectors are really like litteral strings and get passed as string at run-time to the target object who knows what method it refers to ...
     

Share This Page