Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: Adding objects to NSArray within a for loop

I'm trying to loop through an array (compare Addr), and find the matching Strings (currentAddr) and trying to put only the matvched Strings into another array but i keep getting an error

"No visible @Interface for NSArray declares the selector 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);
like image 935
Taskinul Haque Avatar asked Dec 07 '22 11:12

Taskinul Haque


1 Answers

Define it as mutable

NSMutableArray *matchedAddr=[[NSMutableArray alloc]init];
like image 155
Neo Avatar answered Dec 23 '22 11:12

Neo