Reputation: 3124
MyLoginViewController
is a subclass of PFLogInViewController
.
logInViewController
is an object of type MyLogInViewController
in MainViewController.m
i.e.
// MainViewController.m
MyLogInViewController *logInViewController = [[MyLogInViewController alloc] init];
logInViewController.delegate = self;
logInViewController.fields = PFLogInFieldsUsernameAndPassword |
PFLogInFieldsTwitter |
PFLogInFieldsFacebook |
PFLogInFieldsSignUpButton |
PFLogInFieldsDismissButton;
As you can see the fields property
is being set here in MainViewController.m
I want to set this in MyLogInViewController
, so that every MyLogInViewController
object has it set.
However, fields is of type readonly
As seen from : https://www.parse.com/docs/ios/api/Classes/PFLogInView.html#//api/name/fields
@property (nonatomic, readonly, assign) PFLogInFields fields
How can I override this? (I have thought about using a custom getter - but don't know how to execute properly)
Is what I'm trying to do considered bad practice, if so, why?
Edit: Turns out I was looking at the View Documentation not the ViewController Documentation. Thanks to mrt for spotting this.
Upvotes: 1
Views: 588
Reputation: 623
If someone did something readonly, and they know what they are doing, that probably means it really shouldn't be set outside of the class. However, there may still be some reasons to do what you want to do. Why don't you do that in init method though?
Edit:
The fields property in PFLogInViewController can be set. So you can do this in your MyLogInViewController class init method
- (id)init
{
self = [super init];
if (self) {
// Do aditional init stuff
self.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsSignUpButton | PFLogInFieldsDismissButton;
}
return self;
}
this way, you won't be interfering with the internals of the class.
Upvotes: 1
Reputation: 6342
Have you tried to declare
@property (nonatomic, readwrite, assign) PFLogInFields fields
in your subclass?
Upvotes: 0