Just learning

Discussion in 'iOS Programming' started by joatmon, Nov 5, 2013.

  1. joatmon, Nov 5, 2013
    Last edited: Nov 5, 2013

    joatmon macrumors newbie

    Joined:
    Nov 5, 2013
    #1
    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
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Post ViewController.h.

    Post the entire method in ViewController.m where the warning occurs, rather than just two isolated lines from it.
     
  3. joatmon thread starter macrumors newbie

    Joined:
    Nov 5, 2013
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    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.
     
  5. joatmon thread starter macrumors newbie

    Joined:
    Nov 5, 2013
    #5
    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!
     

Share This Page