2

Running into a bit of an issue.

This is my first time really dealing significantly with an AppDelegate.h/.m file.

I've declared a property @property float centerFreq in AppDelegate.h. Then I synthesize it in AppDelegate.m like so: @synthesize centerFreq = _centerFreq. However, when I try to actually use centerFreq later on in AppDelegate.m, I get the error "Use of undeclared identifier 'centerFreq'". I don't understand why I can't use this variable anywhere in my .m file.

Roshan Krishnan
  • 187
  • 1
  • 3
  • 13

1 Answers1

1

foo = self.centerFreq will call the getter that is automatically created. Equivalent to foo = [self centerFreq]. _centerFreq will access the instance variable (iVar) directly. In general, if you have created an @property you want to use the accessor methods centerFreq and setCenterFreq, which are called if you use self.centerFreq as the lvar or rvar in an assignment operation. (self.centerFreq = foo calls [self setCenterFreq:foo]).

@synthesize centerFreq = _centerFreq is unnecessary unless you have implemented both the getter and setter methods for the @property, as _centerFreq is the default name for the backing iVar. If you wanted to choose a different name for the iVar, then @synthesize would be useful.

stevesliva
  • 5,351
  • 1
  • 16
  • 39
  • When I try to do this, it says "use of undeclared identifier 'self'". I didn't think I had to declare self anywhere...I thought it just was? – Roshan Krishnan Sep 06 '14 at 17:06
  • Your method declaration may be C function format rather than Objective-C method format (you need a - before the return type for an instance method) or you may just have some other syntax error. Impossible to say for sure without code. – stevesliva Sep 06 '14 at 19:14
  • Ah, well that's the issue, then. The method is written in C. This poses an interesting problem, though, because I'm using a Core Audio struct that needs to be in C- I may be better off asking it separately. Thank you for your help. – Roshan Krishnan Sep 07 '14 at 03:28