-3

I'm trying to add a NSMutableDictionary to _ons variable with a block parameter but after addObject always returns null.

@property (atomic, strong) NSMutableArray * ons;

--------------------------------------------------------------------

NSMutableDictionary *on = [[NSMutableDictionary alloc] init];
[on setObject:eventName forKey:@"eventName"];
[on setObject:[callback copy] forKey:@"callback"]; // callback it's a block

[_ons addObject:on];
NSLog(@"_ons: %@", _ons); // always prints null!!!
Lebyrt
  • 1,376
  • 1
  • 9
  • 18
Simón Urzúa
  • 1,556
  • 2
  • 11
  • 16
  • possible duplicate of [NSMutableArray addObject not working](http://stackoverflow.com/questions/1827058/nsmutablearray-addobject-not-working) – Martin R May 05 '14 at 15:27

1 Answers1

0

You are never instantiating _ons. Somewhere in your code, you need to call:

self.ons = [[NSMutableArray alloc] init];

(In case you’re new to Objective-C, your code wasn’t crashing because messages to nil are no-ops that return 0, instead of crashing like in some other languages.)

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82