1

I get an error when I use objectForKeyedSubscript: as a class level method, so in my class "MyExample.h/.m" I have something like the following:

+ (id)objectForKeyedSubscript:(NSString*)key;

and I want to do MyExample[@"key"], I initialize a static dictionary in a class method.

Are objectForKeyedSubscript: and the brackets meant to only be used with objects? Is there an alternative way to do it on a class level?

jscs
  • 63,694
  • 13
  • 151
  • 195
Jimmy
  • 10,427
  • 18
  • 67
  • 122
  • Your intuition that this should work is correct; classes _are_ objects in ObjC. They are instances of their "metaclass". – jscs Sep 09 '14 at 20:50
  • Yup. I just noticed the other question (didn't come up in my search). Do you know what @Cy-4AH means in his answer http://stackoverflow.com/questions/23440600/is-it-possible-to-add-keyed-subscripting-to-class-objects#comment35943055_23440600 – Jimmy Sep 09 '14 at 20:55
  • I think e's talking about something like this: [Global variables for class methods](http://stackoverflow.com/a/8498798/). Or maybe just your [basic ObjC "singleton"](http://stackoverflow.com/questions/145154/what-should-my-objective-c-singleton-look-like). – jscs Sep 09 '14 at 20:58

0 Answers0