efpies
efpies

Reputation: 3725

Should I use strong properties for properties with custom getters and setters?

I store some data in NSUserDefaults and keychain and I have a wrapper. For example

- (NSString *)userPassword
{
    return [UICKeyChainStore stringForKey:KEY_USER_PASSWORD];
}

- (void)setUserPassword:(NSString *)userPassword
{
    [UICKeyChainStore setString:userPassword forKey:KEY_USER_PASSWORD];
}

How should properties definition look like? Now I use as follows

@property (nonatomic, strong) NSString *userEmail;

But now I have a doubt if I should use strong statement there since I haven't an ivar for it.

Thanks in advance.

Upvotes: 0

Views: 123

Answers (2)

hites
hites

Reputation: 159

You can use strong properties. Here you are implementing your own setter and getter which means you are only overriding the methods of compiler so If you want to use you can else it is also fine.

Upvotes: 0

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

strong or weak both will be fine.

Its your custom method, this implies that you are overriding the compiler's method, or rather compiler will not create methods for those properties.

EDIT:

One more thing for you :)

Is there any advantage of having atomic property for saving in keychains/userdefaults?

Upvotes: 1

Related Questions