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

Access control leakage when using MutableProperty as a property wrapper #795

Closed
petrpavlik opened this issue Jun 12, 2020 · 2 comments
Closed

Comments

@petrpavlik
Copy link
Contributor

#781 allows usage of properties as property wrappers, which is amazing. There's an issue that prevents me from migrating my code to it though.

My view models generally look like this

class ViewModel {
    private(set) lazy var profile = Property<Profile>(mutableProfile)
    private let mutableProfile: MutableProperty<Profile>

    init(profile: Profile) {
        mutableProfile = MutableProperty<Profile>(profile)
    }
}

this provide compiler guarantees that no code outside of the view model can assign a value to profile in this case. I don't think this can be achieved when using MutableProperty as a property wrapper.

class ViewModel {
    @MutableProperty private(set) var count: Int = 0
}

 let vm = ViewModel()

 // vm.count = 0 // won't compile
 vm.$count.value = 1 // will compile

As much as I'd love to migrate my code to this since it'd make things much simpler, I'm not comfortable doing so it at the expense of losing this compile-time guarantee.

@lukaskubanek
Copy link

@petrpavlik: I haven’t looked into it in detail, but this tweet might be related.

@RuiAAPeres
Copy link
Member

Hello. 👋 Thanks for opening this issue. Due to inactivity, we will soft close the issue. If you feel that it should remain open, please let us know. 😄

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

No branches or pull requests

3 participants