I have been wondering about the following lines of code
[self performSelector:@selector(myMethod) withObject:self afterDelay:1.0];
[self performSelector:@selector(myMethod) withObject:nil afterDelay:1.0];
- Whats the difference between the above 2 lines of code.
- When should we set object as
niland when should we set object asself?
In most cases I have noticed the object to be set as nil.
The difference is whether or not you are passing an object to the selector. All the selector is doing is describing a method.
is different from:
Now if you want the selector (i.e. method) to work on some object that you pass in, say an Array, Dictionary, or class. You use withObject. As in:
You could pass in anything including a reference to the current class (e.g. self), as you did in your example.