Benoit Brulfert
Benoit Brulfert

Reputation: 31

iphone xCode use of undeclared identifier

I just started programming in objective-c and I have a problem with "use of undeclared identifier 'uneImage'; did you mean '_uneImage'?". Lot of post speak about this but I haven't found the solution.

.h :



    #import 


    @interface ViewController : UIViewController 
    {
        UIImagePickerController *picker;
    }

    @property (weak, nonatomic) IBOutlet UIImageView *uneImage;


    - (IBAction)album:(id)sender;
    @end

.m



    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (IBAction)album:(id)sender
    {
        picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:nil];
    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [picker dismissViewControllerAnimated:YES completion:nil];
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end

Upvotes: 2

Views: 6104

Answers (3)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

When you define a property xyz, by default its name is transformed to _xyz to name its backing variable. You can override it with @synthesize name; or even @synthesize name = someOtherName;, but the use of @synthesize is no longer required.

The property itself is visible from the outside, but it does not introduce an unqualified name in the scope the same way the variables do. In other words, you cannot use the property without prefixing it with self, but you can use its backing variable.

To make the long story short, replace

uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

with

_uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

or

self.uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

to make it work.

Upvotes: 5

rmaddy
rmaddy

Reputation: 318774

You don't have an instance variable named uneImage. You have a property with that name and an automatically synthesized instance variable named _uneImage.

So change:

uneImage.image = ...

to either:

self.uneImage.image = ... // use the property

or:

_uneImage.image = ... // use the generated instance variable

Upvotes: 2

Dave
Dave

Reputation: 7717

You are accessing a property, so you need to put "self" in front of the variable:

self.uneImage.image = ....

Upvotes: 0

Related Questions