Joe Casini
Joe Casini

Reputation: 141

UITextField "Expected identifier" issue

I'm new to obj-c and I'm trying to code a simple "inputs to plist" app. I have two inputs:

@property (strong, nonatomic) IBOutlet UITextField *costo;
@property (strong, nonatomic) IBOutlet UITextField *descrizione;

and I synthesize them in the .m file

@synthesize costo;
@synthesize descrizione;

then I have a function saveData() with:

NSNumber *newValue = [NSNumber numberWithInt:[costo.text intValue]];
[mutableDictCopy setObject:newValue forKey:[descrizione.text]];

this function works fine with costo.text, but then I get an "Expected identifier" error with descrizione.text. if I switch it with @"foo", all goes fine and it updates my plist. Where do I get wrong?

Upvotes: 1

Views: 179

Answers (2)

Vishal
Vishal

Reputation: 556

Use This

   [mutableDictCopy setObject:newValue forKey:descrizione.text];

instead of

[mutableDictCopy setObject:newValue forKey:[descrizione.text]];

Upvotes: 3

Jirka Hanika
Jirka Hanika

Reputation: 13547

You are mixing the member and message syntaxes. This is OK:

[descrizione text]

The following is also OK. It means the same thing.

descrizione.text

This is not OK:

[descrizione.text]

Upvotes: 1

Related Questions