2

My .h file has

@property (strong,nonatomic) NSString *usertoken;

My .m file has

@synthesize usertoken;

-(void)setUsertoken:(NSString *)usertoken
{
    _usertoken=usertoken;


}

-(NSString *)usertoken
{

}

I am in the process of writing the setters and getters (i.e. they are not done yet). But after writing the line _usertoken=usertoken, Xcode is showing an error for _usertoken:

User of undeclared identifier '_usertoken'; did you mean 'usertoken'?

Does anyone know how I might fix this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

4

The problem is your use of @synthesize.

By simply writing @synthesize usertoken;, an ivar is created that is also just called userToken (no underscore).

If you instead do @synthesize usertoken = _userToken;, it will work correctly.

Dima
  • 23,484
  • 6
  • 56
  • 83
  • The last part of your answer is not correct. If you implement both getter and setter, it will not automatically create an ivar unless you explicitly synthesize one. – Jesse Rusak Jul 14 '14 at 16:55
  • Ah whoops. I actually didn't notice that he did that. Fixing my answer now. – Dima Jul 14 '14 at 16:59