Objective-C – Expected identifier error

2019-04-04 05:28发布

问题:

I'm getting an expected identifier error when I try to compile my code.

careerURL is setup like this in .h file:

@property (nonatomic, copy) NSString *careerURL;

And synthesized like this in .m file:

@synthesize careerURL;

I really do not understand what is the issue here. The exact code works in another viewcontroller.

回答1:

You should either use dot . syntax,

NSString *wtf = self.careerURL;

Or Objective-C message syntax,

NSString *wtf = [self careerURL];

Not both at the same time.



回答2:

You should write:

 NSString *wtf = self.careerURL;

When you are writing [object method] it is expected that you want to call method method from object object. If you want just access some value (that is defined as @property) you can type:

[self nameOfValue];

or

self.nameOfValue;