1

I am trying to modify the NSUserNotifictation to pass custom variables:

@interface MyUserNotification: NSUserNotification
@property (nonatomic) int theid;
@property (nonatomic) NSString* url;
@end

@implementation MyUserNotification
@end

Then when initiating in my AppDelegate object:

MyUserNotification *notification = [[MyUserNotification alloc] init];
notification.theid = theid;

setting theid throws the error:

-[_NSConcreteUserNotification setTheid:]: unrecognized selector sent to instance 0x100204840

Why is NSConcreteUserNotification object getting involved?

maxisme
  • 3,974
  • 9
  • 47
  • 97

1 Answers1

2

so this class isn't meant to be overridden it seems, but good news: there a userInfo dict?

So you can store whatever objects as KV pairs in a userInfo dict...

int theid;
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@(theid) forKey:@"theid"];
notification.userInfo = userInfo;
Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • 1
    Cheers I will use: https://developer.apple.com/reference/foundation/nsusernotification/1415675-userinfo just got excited about customising objects – maxisme Dec 21 '16 at 14:32
  • 1
    @Maximilian the reason that it works this way will never be apparent to us mortals, but it is implemented with class clusters, and usually we never need to know the "why". – Grady Player Dec 21 '16 at 14:37