Objective c 自定义NSUserNotification对象
我正在尝试修改NSUserNotification以传递自定义变量:Objective c 自定义NSUserNotification对象,objective-c,macos,cocoa,nsusernotification,Objective C,Macos,Cocoa,Nsusernotification,我正在尝试修改NSUserNotification以传递自定义变量: @interface MyUserNotification: NSUserNotification @property (nonatomic) int theid; @property (nonatomic) NSString* url; @end @implementation MyUserNotification @end 然后在myAppDelegate对象中启动时: MyUserNotification *noti
@interface MyUserNotification: NSUserNotification
@property (nonatomic) int theid;
@property (nonatomic) NSString* url;
@end
@implementation MyUserNotification
@end
然后在myAppDelegate
对象中启动时:
MyUserNotification *notification = [[MyUserNotification alloc] init];
notification.theid = theid;
设置ID将抛出错误:
-[_NSConcreteUserNotification setTheid:]: unrecognized selector sent to instance 0x100204840
为什么
NSConcreteUserNotification
对象被卷入其中?所以这个类似乎不应该被覆盖,但好消息是:有一个dict
因此,您可以将任何对象存储为用户信息目录中的KV对
int theid;
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@(theid) forKey:@"theid"];
notification.userInfo = userInfo;
我将使用的干杯:刚刚对定制感到兴奋objects@Maximilian它以这种方式工作的原因对我们凡人来说永远不会是显而易见的,但它是通过类集群实现的,通常我们不需要知道“为什么”。