Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put an ObjectiveC @selector in a NSDictionary?

[actionMap setObject:@selector(actionNavPop) forKey:@"navPop"];

This doesn't work. NSDictionary can only hold objects, and a SEL type is not an object.

For number types you can do [NSNumber numberWithInt:123] but is there any sort of similar object wrapper for selectors?

like image 453
Alex Wayne Avatar asked Jan 21 '10 20:01

Alex Wayne


People also ask

How do I create an NSDictionary in Objective-C?

Creating NSDictionary Objects Using Dictionary Literals In addition to the provided initializers, such as init(objects:forKeys:) , you can create an NSDictionary object using a dictionary literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:forKeys:count:) method.

Does NSDictionary retain objects?

An NSDictionary will retain it's objects, and copy it's keys. Here are some effects this has had on code I've worked on. Sometimes you get the same object you put in, sometimes not. Immutable objects are optimized to return themselves as a copy .

How do you add value in Nsmutabledictionary?

[myDictionary setObject:nextValue forKey:myWord]; You can simply say: myDictionary[myWord] = nextValue; Similarly, to get a value, you can use myDictionary[key] to get the value (or nil).

What is ID in Obj C?

“id” is a data type of object identifiers in Objective-C, which can be use for an object of any type no matter what class does it have. “id” is the final supertype of all objects.


1 Answers

Use NSStringFromSelector() and NSSelectorFromString().

like image 70
Rob Napier Avatar answered Nov 04 '22 14:11

Rob Napier