IOS 7 - Local declaration hides instance variable when invoking database query results

I have this function that accepts the results of a database query. I am using the FMDB library to query the database. However, I get the feeling that I am not passing the query results correctly to my mutable array. Here is my fucntion

-(NSArray *)initializeGroupIDArray{
    // Getting the database path.
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [paths objectAtIndex:0];
    NSString *dbPath = [docsPath stringByAppendingPathComponent:@"itemList.db"];

    FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
    [database open];

    NSString *sqlSelectQuery = @"SELECT DISTINCT GROUPID FROM ItemList";

    // Query result
    FMResultSet *resultsWithNameLocation = [database executeQuery:sqlSelectQuery];

    while([resultsWithNameLocation next]) {
        NSString *itemName = [NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"GROUPID"]];

        // loading your data into the array, dictionaries.
        NSLog(@"GroupID = %@", itemName);
        [groupArray addObject:itemName];
    }
    [database close];

    NSArray *groupID;
    [groupID = groupArray copy];

    return groupID;
}

A warning appears in the lines of NSLog(@"GroupID = %@", itemName);and [groupArray addObject:itemName];stating that the local declaration is itemNamehiding the instance variable. I have a feeling that behind this I cannot properly add the results to my array. Can someone point out what I'm doing wrong? Thank.

+3
source share
1 answer

itemName , , . , itemName, itemName NSLog addObject: ( , , ).

, NSString *itemName .

+5

All Articles