objective c - Dictionary Scope? -


i'm declaring dictionary this:

@property (weak, nonatomic) nsmutabledictionary *testvariablevalues; @synthesize testvariablevalues = _testvariablevalues; 

then, i'm populating dictionary this:

- (ibaction)testpressed:(uibutton *)sender { self.testvariablevalues = [nsmutabledictionary dictionary]; if ([sender.currenttitle isequaltostring:@"test 1"]) { [self.testvariablevalues setobject:[nsnumber numberwithdouble:5.2] forkey:@"x"]; [self.testvariablevalues setobject:[nsnumber numberwithint:-1] forkey:@"y"]; [self.testvariablevalues setobject:[nsnumber numberwithint:1] forkey:@"a"]; } else if ([sender.currenttitle isequaltostring:@"test 2"]) { // continues 

each time populate dictionary i'm printing contents of dictionary command line know that part working, problems seem arise if i'm trying access dictionary method, this:

if ([self.display.text isequaltostring:@"x"]) { nslog(@"%f", [[self.testvariablevalues objectforkey:@"x"] doublevalue]); [self.brain pushoperand:[[self.testvariablevalues objectforkey:@"x"] doublevalue]]; 

the nslog in block of code returns null, makes me think can't access dictionary outside testpressed method. able shed light on this? implementation of dictionary wrong?

thanks!

your dictionary should strong property, since if make weak, ditionary freed time testpressed method ends execution

you should change

@property (weak, nonatomic) ... 

to

@property (strong, nonatomic) ... 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -