0

I've declared a property in the .h file called cellTitles. In my .m file, I have a method as follows:

-(NSArray *)cellTitles
{
    if(!_cellTitles){
        _cellTitles = [[NSArray alloc] initWithObjects:@"several strings", nil];
        NSLog(@"Home Array Created");
    }
    return _cellTitles;
}

But the array is not created when I refer to _cellTitles or self.cellTitles. I have several NSLogs that all say the array has 0 objects. Do I need more than this. Some answers have said I need to synthesize, but as I understand it, that is no longer necessary.

Bhumeshwer katre
  • 4,671
  • 2
  • 19
  • 29

1 Answers1

0

Make sure your property is assigned strongly.

@property (nonatomic, strong) NSArray *cellTitles;
karlofk
  • 1,205
  • 8
  • 15
  • this is not right, you can have a weak property lazy loaded if you want – wattson12 Dec 05 '13 at 15:21
  • True, but in this case it doesnt seem like the any other object holds a strong reference to the array. Edited the answer. – karlofk Dec 05 '13 at 15:24
  • 1
    Most of the time you want objects which have mutable subclasses to be `copy` .. just saying ;) – HAS Dec 05 '13 at 15:39