views:

90

answers:

1

I have a method

-(void)myMethod:(MyObject*)obj

And I am detaching a new thread

[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];

How can I pass a MyObject* through @selector(myMethod)?

+5  A: 
[NSThread detachNewThreadSelector:@selector(myMethod:) toTarget:self withObject:myObjectInstance];

You will definitely want that @selector(myMethod:) instead of @selector(myMethod). They mean different things.

Giao
Should have seen the withObject parameter. Thanks for the tip.
Sheehan Alam
@Sheehan Alam: You should accept this answer then :p
Jason Coco
More explicitly, the selector is the *name* of the message you're sending. The `:` is part of the method's name and thus part of the selector. You can have a method named `myMethod` and one named `myMethod:` live right alongside each other with no confusion — they're no more similar to the compiler than `kill` and `skill`. In fact, in Smalltalk (which Obj-C was based on), this is how getters and setters were normally written.
Chuck