Objective-C:在for循环中向NSArray添加对象

时间:2012-10-01 09:50:20

标签: objective-c loops nsarray

我正在尝试遍历一个数组(比较Addr),并找到匹配的字符串(currentAddr),并尝试只将匹配的字符串放入另一个数组但我一直收到错误

“NSArray没有可见的@Interface声明选择器addObject”

NSArray *matchedAddr;
//NOTE: multiple addresses from compareAddr[i] may match to multiple stored Addresses
for (NSUInteger i = 0; i < [compareAddr count]; i++)
{
    //Checking IF the obtained key (Mac Address) at compareAddr[i] matches one of the stored Addresses
    NSString *currentAddr = [compareAddr objectAtIndex:i];
    BOOL addrExists = ([[dictionaryOfAddresses     objectForKey:@"StoredAddr"]objectForKey:currentAddr] != nil);

    if (addrExists)
    {   
        NSLog (@"Match found at index %1u", i);
        [matchedAddr addObject:currentAddr];
    }

    else { NSLog(@"No Value matches at index %i \n", i); }
}
NSLog (@"Array of matched addresses for further processing %@", matchedAddr);

1 个答案:

答案 0 :(得分:16)

将其定义为可变

NSMutableArray *matchedAddr=[[NSMutableArray alloc]init];