I have a class with the following header:
#import <Foundation/Foundation.h>
@interface CustomClass : NSObject
@property (strong, nonatomic) NSString *foo;
@end
With the following implementation that does not show any errors:
#import "CustomClass.h"
@implementation CustomClass
- (void) setFoo:(NSString *)foo {
_foo = foo;
}
@end
Being a complete beginner to Objective-C, I am baffled when I add the following method to the implementation:
- (NSString *)foo {
return _foo;
}
because now there is an error in the method use of undeclared identifier 'title'
and it recommends that I change _foo
to foo
. Not only does it say that in the newly added method, it also says it in the previous setter method. I have tried to look up the situation and I have not found a satisfactory response. Related questions talk about @synthesize
, but I have read that it is not necessary, so I am not sure what the problem is.
Thanks in advance!
-GoldDove