-2

I want to implement something like this

 [self perform Selector:@selector(setEarlierMessagesIsLoading:) withObject:@YES afterDelay:1];

But it not working. Why? Is it possible ?

Resolved with

 [self perform Selector:@selector(setEarlierMessagesIsLoading:) withObject:YES afterDelay:1];
  • possible duplicate of [iPhone: performSelector with BOOL parameter?](http://stackoverflow.com/questions/7075620/iphone-performselector-with-bool-parameter) – dan Jul 20 '15 at 14:57
  • You are sending an `NSNumber` instance to `setEarlierMessagesIsLoading:` method – Luca D'Alberti Jul 20 '15 at 15:05
  • Define "not working". Show your `setEarlierMessagesIsLoading:` method. Explain what is happening compared to what you expect to happen. – rmaddy Jul 20 '15 at 16:28
  • BTW - using `dispatch_after` is much clearer and easier than using `performSelector:withObject:afterDelay:`. – rmaddy Jul 20 '15 at 16:29
  • 1
    Your "resolution" is not valid. Do not do what you propose. – rmaddy Jul 20 '15 at 20:47
  • 1
    Your "resolution" is not valid. Try my answer, do not do things by guessing. – ronan Jul 21 '15 at 01:31

2 Answers2

3

First of all, @YES is not a BOOL value, it is an instance of NSNumber.

So if you wanna get a bool value, you have to convert it to a BOOL value.

in you selector

- (void)setEarlierMessagesIsLoading:(NSNumber *)isLoading {
    if([isLoading boolValue]) {
        NSLog(@"Is it loading? YES");
    }else {
        NSLog(@"Is it loading? NO");
    }
}
ronan
  • 1,611
  • 13
  • 20
  • 2
    Do not code your `if/else` like that. Instead, simply do: `if ([isLoading boolValue]) { // YES } else { // NO }`. Never directly compare a `BOOL` value against `YES` or `NO`. – rmaddy Jul 20 '15 at 16:31
  • @rmaddy Thank you for pointing out my insufficient. You're awesome. – ronan Jul 20 '15 at 16:45
0

Im guessing your method looks like this:

- (void)setEarlierMessagesIsLoading:(BOOL)isLoading;

Change to:

- (void)setEarlierMessagesIsLoading:(NSNumber *)isLoading;

Since you are sending in a NSNumber * and not a BOOL.

Peter Segerblom
  • 2,773
  • 1
  • 19
  • 24