Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store non-objects in a dictionary?

Tags:

objective-c

I tried storing a selector(SEL) in a NSMutableDictionary and it caused a crash, probably because the dictionary tries to dereference it as an object pointer. What is the standard recipe for storing non-objects in a dictionary?

like image 360
airportyh Avatar asked Dec 03 '22 04:12

airportyh


1 Answers

You can convert selectors to NSString using NSStringFromSelector() and you can go back the other way with NSSelectorFromString().

SEL aSel = @selector(takeThis:andThat:);

[myDict setObject:NSStringFromSelector(aSel) forKey:someKey];

SEL original = NSSelectorFromString([myDict objectForKey:someKey]);
like image 79
dreamlax Avatar answered Dec 29 '22 08:12

dreamlax