Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joatmon

macrumors newbie
Original poster
Nov 5, 2013
3
0
New to obj c. VERY simple class declaration and method call. I'm getting a warning: Local declaration of 'cameraView' hides instance variable

Can't see why this is happening. Can someone enlighten me? Thanks!

CameraView.h
Code:
#import <Foundation/Foundation.h>

@interface CameraView : NSObject {
}

- (void) sayHello;

@end
CameraView.m
Code:
#import "CameraView.h"

@implementation CameraView

- (void) sayHello {
    NSLog(@"Hello!");
}
@end

In ViewController.m
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    CameraView *cameraView = [[CameraView alloc] init];
    [cameraView sayHello]; //<-- warning is on this line
}

ViewController.h
Code:
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
#import "CameraView.h"

@interface ViewController : GLKViewController {
    CameraView *cameraView;    //<-- This is the problem. Thanks, ArtOfWarfare!
}

@end
 
Last edited:
Post ViewController.h.

Post the entire method in ViewController.m where the warning occurs, rather than just two isolated lines from it.
 
Done. Thanks for looking at it.

Can you post all of your ViewController.h file, too? This warning means that you've used the name "cameraView" somewhere outside of viewDidLoad and that you're, potentially by mistake, writing over it with a new value instead of viewDidLoad.
 
Sure. I'll post that code for others who might make such a rookie mistake, but you solved my problem. I had a variable also called cameraView declared as an instance variable in the .h file. Somehow, I thought that I had to do that, but after reconsidering that idea, I realize how dumb that is.

Thanks for the tip. Problem solved!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.