amit soni
amit soni

Reputation: 2163

Class Object is always null

This is the method when my app complete the downloading with contact which is coming from server. In for loop I am using AIContactParsarModal class and using dictionary I am setting the objects, but every time object value is null.

Thanks for the help and any help will be appreciable. Here is my code.

- (void)donewithContact {

    self.allPersonDetailsDict = [[NSMutableDictionary alloc]initWithCapacity:1];
    NSMutableArray *allKeysArray = [[NSMutableArray alloc] init];

    NSString *prefix;

    NSString *searchContactString = [[NSUserDefaults standardUserDefaults] objectForKey:@"AdvanceSearch"];
    if ([searchContactString isEqualToString:@"SpecialSearch"]) {
        [self.allPersonDetailsDict removeAllObjects];
    }
    if (getContactArray.count == 0 ){
        [noContactLabel setHidden:NO];
    } else {
        for (AIContactParsarModal *contact in getContactArray) {
            NSLog(@"contact LAST NAMES ARE %@",contact.lastName);
            prefix = [[contact.lastName substringWithRange:NSMakeRange(0, 1)] uppercaseString];

            if ([allKeysArray containsObject:prefix]) {
                NSMutableArray *conatctsWithPrefix = [_allPersonDetailsDict objectForKey:prefix];
                [conatctsWithPrefix addObject:contact];
            } else {
                [allKeysArray addObject:prefix];
                NSMutableArray *conatctsWithPrefix = [[NSMutableArray alloc] initWithObjects:contact,nil];
                [self.allPersonDetailsDict setObject:conatctsWithPrefix forKey:prefix];
                NSLog(@"conatctsWithPrefix %@",conatctsWithPrefix);
            }
        }
    [noContactLabel setHidden:YES];
    }
    NSLog(@"All Names First characters are:%@", allKeysArray);

    [self.contactTableView reloadData];
    [HUD hide:YES];
}

Upvotes: 0

Views: 110

Answers (1)

Gajendra Rawat
Gajendra Rawat

Reputation: 3663

May be you are getting null value in contact by which you are getting null in conatctsWithPrefix

first print values stored in contact.

Upvotes: 1

Related Questions