Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow public getter and private setter for properties #14310

Closed
miniak opened this issue Feb 25, 2017 · 1 comment
Closed

Allow public getter and private setter for properties #14310

miniak opened this issue Feb 25, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@miniak
Copy link

miniak commented Feb 25, 2017

Example:

class Foobar {
    private _value = 0;

    public get value() {
        return this._value;
    }

    private set value(value: number) {
        console.log(`setting value to: ${value}`);
        this._value = value;
    }

    public doSomething() {
        this.value = this.value + 1;
    }
}

You can do that for example in Objective-C, where it's really useful:

Foobar.h

@interface Foobar : NSObject
@property (readonly, nonatomic) int value;
- (void)doSomething;
@end

Foobar.m

@interface Foobar () {
    int _value;
}
@property (readwrite, nonatomic) int value;
@end

@implementation Foobar

- (int)value {
    return _value;
}

- (void)setValue:(int)value {
    NSLog(@"setting value to: %d", value);
    _value = value;
}

- (void)doSomething {
    self.value = self.value + 1;
}

@end
@mhegazy
Copy link
Contributor

mhegazy commented Feb 27, 2017

Duplicate of #2845

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 27, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants