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

Implement didSet and willSet observable properties #22

Closed
angelolloqui opened this issue Oct 19, 2017 · 1 comment
Closed

Implement didSet and willSet observable properties #22

angelolloqui opened this issue Oct 19, 2017 · 1 comment

Comments

@angelolloqui
Copy link
Owner

angelolloqui commented Oct 19, 2017

In Swift, as part of the language, a property can have a didSet and/or willSet. Example:

class A {
    var isLocating = false {
        didSet {
            delegate.set(isLocating: isLocating) 
        }
    }
}

In Kotlin there is no default way of expressing property observers but can be done with delegated properties or by writing a custom setter (https://stackoverflow.com/a/39842353/378433)

For simplicity, implement a custom setter like:

class A {
    var isLocating = false
        set(value) {
            field = value
            delegate.set(isLocating = value)
        }
}

In case of willSet, just write the code before the field = value assignment

@angelolloqui
Copy link
Owner Author

Implemented in 8d6c593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant