无法将NSDictionary添加到NSArray

Gab*_*ter 1 arrays cocoa-touch objective-c ios

我正在尝试向数组添加字典以在字典上创建数组,但是当我测试应用程序时,数组仍然是空的.看看我的代码:

NSMutableArray *listaEstabelecimentosPorCategoria;


    for (NSDictionary *tempDict in listaEstabelecimentos) {

        if ([[tempDict objectForKey:@"category"] integerValue] == 1) {
            [listaEstabelecimentosPorCategoria addObject:tempDict];

            NSLog(@"TEST");
        }
    }

    NSLog(@"%@", listaEstabelecimentosPorCategoria);
Run Code Online (Sandbox Code Playgroud)

该应用程序打印此:

2013-08-18 12:16:38.802 Petro?polis[10157:c07] TEST
2013-08-18 12:16:38.802 Petro?polis[10157:c07] TEST
2013-08-18 12:16:38.803 Petro?polis[10157:c07] (null)
Run Code Online (Sandbox Code Playgroud)

das*_*ght 6

当我测试应用程序时,数组仍然是空的.

这是因为你没有初始化listaEstabelecimentosPorCategoria:

NSMutableArray *listaEstabelecimentosPorCategoria = [NSMutableArray array];
Run Code Online (Sandbox Code Playgroud)