ReactiveCocoa / ReactiveSwift

Streams of values over time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access control leakage when using MutableProperty as a property wrapper

petrpavlik opened this issue · comments

#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.

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

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. 😄