iphone - where do I initialize NSMutable Dictionary? -
i have array comprised of farther sub-arrays
i want display summary of contents of sub-arrays tableview count of occurrences of each entry. have determined best , easiest way through nsmutabledictionary intermediate step.
i declare dictionary in implementation
@implementation reviewviewcontroller { nsmutabledictionary *dict; } and downwards in methods initialise , utilize so:
dict = [nsmutabledictionary new]; [dict setobject:[observation entrycount] forkey:[observeditem species]]; the swapping of key , object deliberate count want. i'm using fact values retained, keys overwritten, if swap them round curation free.
it works!, every time method invoked, dictionary clobbered re-initalization lastly thing entered. anywhere else , falls out of scope.
if pass arguement in method name instead, message "local declaration of 'dict' hides instance variable ". code irreducable set of parts, so
so, right place instantiation?
i'd love create contribution here meaningful thanks, before can i'm going silly such questions.
you initialise in init method. view controller following:
- (id)initwithnibname:(nsstring*)nibname bundle:(nsbundle*)bundle { if ((self = [super initwithnibname:nibname bundle:bundle])) { dict = [nsmutabledictionary new]; } homecoming self; } i don't understand mean "anywhere else , falls out of scope.". it's instance variable. hence in scope in method in class.
by way, name instance variables underscore prefix, e.g. _dict. mutual convention , helps remember when using it's instance variable.
iphone nsmutabledictionary
No comments:
Post a Comment