将选择器作为值存储在NSDictionary中 [英] Store selector as value in an NSDictionary

查看:103
本文介绍了将选择器作为值存储在NSDictionary中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 NSDictionary 中存储选择器,而不将其存储为 NSString


Is there a way to store a selector in an NSDictionary, without storing it as an NSString?

推荐答案

SEL 只是一个指针,可以存储在 NSValue

SEL is just a pointer, which you could store in an NSValue:

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 
                       [NSValue valueWithPointer:@selector(foo)], @"foo",
                       nil];

要取回选择器,您可以使用:

To get the selector back, you can use:

SEL aSel = [[dict objectForKey:@"foo"] pointerValue];

这篇关于将选择器作为值存储在NSDictionary中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆