user3570727
user3570727

Reputation: 10213

Property declaration craziness iOS 7

I am at my wits end with a property declaration in a iOS class. In my .h file I have the following declaration :

@property (strong, nonatomic)NSString *sessionID;

In my .m file I have this code :

- (void)setSessionID:(NSString *)aSessionID
{
_sessionID = aSessionID;
// Custom code to set this in a global context
}

This is all fine and compiles with no issues. Now I need to have the sessionID return a default value if nothing is set, however the moment I add this line :

- (NSString *)sessionID
{
    return _sessionID ? _sessionID : @"defaultSession";
}

then the first line in the setSessionID:

_sessionID = aSessionID;

causes an error with "Use of undeclared function _sessionID. Did you mean aSessionID", I am at my wits end to figure out what is causing it.. I have so many classes with variables and have never seen this before... what is causing this? I restarted Xcode, cleaned out the project and no luck.. If I remove the - (NSString *)sessionID method, then it stops complaining.. but the moment I add the method declaration the Xcode marks it as an error.

Anypointers accepted! :)

Edit: I also noticed, that in this class if I add any property accessor method it complains about the ivar.. e.g. I have another property declared

@property (strong, nonatomic) NSString *userEmail

The moment I add -(NSString *)userEmail, the ivar _userEmail usage above it all becomes undeclared.. :(

Upvotes: 1

Views: 102

Answers (1)

rdelmar
rdelmar

Reputation: 104092

If you override both the setter and getter of a property, the compiler will not automatically synthesize the backing ivar for you. You need to do a manual synthesis,

@synthesize sessionID = _sessionID;

Upvotes: 6

Related Questions