Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 自定义NSUserNotification对象_Objective C_Macos_Cocoa_Nsusernotification - Fatal编程技术网

Objective c 自定义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

我正在尝试修改NSUserNotification以传递自定义变量:

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

@implementation MyUserNotification
@end
然后在my
AppDelegate
对象中启动时:

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它以这种方式工作的原因对我们凡人来说永远不会是显而易见的,但它是通过类集群实现的,通常我们不需要知道“为什么”。