-1

I have the next code:

-(void)accountAdded:(GoogleMailAccount *)account
{
    DLog(@"accountAdded %@ ",account.emailAddress);

     DLog(@"_accounts addObject %@ ",account);
    [_accounts addObject:account];

     DLog(@"_accounts count %d",[_accounts count]);

    [_subFolders setValue:[account subscribedFolders] forKey:account.emailAddress];

    [self refreshTableViewTree];
}

and the next log output for it:

2013-08-02 00:57:28.009 MailClient[9327:11603] accountAdded iosmailclienttest@gmail.com 
2013-08-02 00:57:28.010 MailClient[9327:11603] _accounts addObject <GoogleMailAccount: 0x7db94f0> 
2013-08-02 00:57:28.011 MailClient[9327:11603] _accounts count 0

Why accounts size = 0? (It's a real problem for me :( .What I don't see???)

Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70
pvllnspk
  • 5,667
  • 12
  • 59
  • 97
  • 1
    Is the array _accounts nil? In ObjC you can send messages to nil, so it wouldn't give an error if it was nil and you called a method on it – guitarflow Aug 01 '13 at 22:10
  • I get it. My bad - I forgot again about the NullPointerException missing in the language. Thanks. – pvllnspk Aug 01 '13 at 22:12
  • @Abdullah Shafique - actually Tom's "Is _accounts != nil?" was enough for understanding my dummy problem. In any case - thanks. – pvllnspk Aug 01 '13 at 22:16

1 Answers1

3

In start of method:

 if(!_accounts) _accounts = [[NSMutableArray alloc]init];

Or you can do in:

-(NSMutableArray *)accounts
{
    if(!_accounts) _accounts = [[NSMutableArray alloc]init];
    return _accounts;
}
Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70