Search code examples
cocoansbundle

warning on nsbundle bundlepath


i want to get the executable path of my bundle. (i want to get the path so i can load images in a NSImageView)

i got this.

NSString * _Ruta_APP = [[NSString alloc] init];
_Ruta_APP = [[NSBundle mainBundle] bundlePath];

but the compiler says /ControlAPP.m:33:0 /ControlAPP.m:33: warning: local declaration of '_Ruta_APP' hides instance variable

but i cannot use the value of _Ruta_APP

anyone has an idea?


Solution

  • If you really wanted to keep the path in an instance variable, just kill the first line.

    1. You don’t have to declare an instance variable in a method.
    2. You don’t have to initialize a variable with an empty string before assigning another string.
    3. You should then retain the instance variables object:

    [_Ruta_APP autorelease];
    _Ruta_APP = [[[NSBundle mainBundle] bundlePath] copy];